Skip to content
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

Improve error message for autocast error at Var assign #10327

Conversation

straight-shoota
Copy link
Member

When an symbol as default argument to an enum restriction can't be autocasted, the error message doesn't properly reflect this use case and is more generic:

enum Foo
  FOO
end

def foo(foo : Foo = :bar) # Error: can't restrict Symbol to Foo
end

In this situation the intention is pretty clear, the symbol is supposed to be autocasted to the matching enum member. When that doesn't succeed, the error is most likely because the requested enum member doesn't exist because of a typo, merge conflict or similar.

So this patch generates a more appropriate error message: can't autocast :bar to Foo: no matching enum member

@straight-shoota straight-shoota force-pushed the feature/compiler-enum-autocast-default-value branch from 1a36f99 to e3cbdb7 Compare January 28, 2021 23:51
@bcardiff bcardiff added this to the 1.0.0 milestone Feb 18, 2021
@asterite asterite merged commit d8c490d into crystal-lang:master Feb 18, 2021
@straight-shoota straight-shoota deleted the feature/compiler-enum-autocast-default-value branch February 18, 2021 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants