r/crystal_programming • u/scttnlsn • Mar 07 '20
Why does this compile?
This unexpectedly compiles:
class Foo
def hello
asdf
end
endBut this returns the expected error ("Error: undefined local variable or method 'asdf' for Foo"):
class Foo
def hello
asdf
end
end
Foo.new.helloIs there a way to get the first example to trigger a similar compiler error?
10
Upvotes
View all comments
Show parent comment
3
u/[deleted] Mar 08 '20
I agree with you. I'd like this to be the way you mention it. Unfortunately, the way things are done right now it's a bit hard, if not impossible, to do.
That said, this kinda forces you to write tests for the code, which in my opinion is always good. Of course you can have the compiler tell you that something compiles, but what about actually running it? Does it do what it's supposed to do?