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

Compiler: try literal type in autocast first #9610

Merged
merged 2 commits into from Jul 17, 2020

Conversation

asterite
Copy link
Member

@asterite asterite commented Jul 14, 2020

Fixes #8655

When trying to match Int32 with autocasting enabled against a union type, we should always try to match first using the regular approach (check if Int32 matches any of the union types without autocasting) and then try to match using autocasting. The logic was reversed in the compiler so this fixes that.

So before, the 255 literal, as an Int32, vs UInt8 | Int32 would match both types because of autocasting. Now it only matches Int32 exactly.


it "doesn't autocast number on union (#8655)" do
run(%(
def foo(x : UInt8 | Int32, y : Float64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the union would have been UInt64 | Int64 and the call with Int32, what is the output?

ambiguous call? or any of those types are used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says ambiguous call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, if there is no spec for that it should be added. Other than tat LGTM

@asterite asterite added this to the 1.0.0 milestone Jul 17, 2020
@asterite asterite merged commit f2b2330 into crystal-lang:master Jul 17, 2020
@asterite asterite deleted the bug/autocast-priority branch July 17, 2020 18:12
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.

BUG: trying to downcast (Int32 | UInt8) <- Int32 (Exception)
2 participants