-
-
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
Add detail to errors involving automatic casting of symbols #7284
Comments
@asterite I saw the source code of autocasting and I assume it could be easy to raise proper error in this case? Also please consider |
This is actually a bit hard to implement. The above only considers a method with a single argument. What happens if you have multiple arguments? For example: enum Foo
Bar
Baz
Quux
end
def foo(x : String, arg : Foo)
end
foo(1, :far) Right now you get:
But what, should it also say that the symbol won't match, and list all possible values? What happens if there are multiple arguments that need to be autocast? Should this be shown below the Overloads list? |
Removing symbols and using |
If the argument to be autocast is the first one that fails an overload match, yes, otherwise some other error will be shown as part of #11106. Say: enum Foo
Bar
end
def foo(x : Int32, y : Foo); end
# Error: no overload matches
# Note: failed to match argument #2 against parameter `y : Foo`
# Did you mean `:bar`?
foo(1, :bat)
# Error: no overload matches
# Note: failed to match argument #1 against parameter `x : Int32`
foo("", :bat) |
cc @straight-shoota
When a user calls a function which autocasts a symbol literal as an enum and the symbol name doesn't exist:
The error message is unhelpful, and while it does address the fact that
foo()
doesn't work withSymbol
, it doesn't detect the automatic casting:An extra portion could be added onto the end of this error, listing possible typos that the user may have entered:
The text was updated successfully, but these errors were encountered: