-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler ignores call to undefined method after a NoReturn call #6100
Comments
Even more reduced: |
@RX14, @bew, why do you think that it is a bug? Ruby has the same behaviour because code launches from right to left. Just by nature, Crystal compiler can optomize your code to this: Try this: class Some
def initialize
@foo = 3
@bar = "xxx"
@foo + @bar
end
end
p :success This code compiles correctly and even launches. But if we change last line to |
The def defined_method : Void
if ARGV.size > 0
raise "no"
end
end
undefined_method(defined_method) Always shows |
Whether it's a bug or a feature request is moot: I explained why this behaviour is undesirable above. |
Using def foo
bar return # Syntax error: void value expression
end
foo |
@RX14, I did not say that it is a bug or a feature, i just asked "why". My research led to the hypothesis that LLVM, or GCC, or linker can remove unused functions due to optimization reasons (source 1, source 2). It is nice and it is bad.
Maybe it is better to at least notify user that there is unused code like |
@SlayerShadow it's impossible to compile a function which isn't called in crystal. That's a limitation of the typing algorithm (nothing to do with llvm, gcc, linker, etc). That's never going to change. See #4402. And What i'm thinking is essentially an enhancement: at least look up the method names to see if they exist in scope, even if we can't type them. |
@RX14, thank you for detailed answer. |
It's a feature. If the type is |
@asterite I explained up above (and I agree on your method of fixing it): the |
The above example compiles and runs despite there being a call to an undefined method in the body. This is annoying when
undefined_method
is actually intended to be a macro call and can lead to renaming a macro definition, but not renaming a usage silently succeeding where it should fail to compile.The text was updated successfully, but these errors were encountered: