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

Fix: Do not merge union types in truthy filter #12752

Merged

Conversation

straight-shoota
Copy link
Member

Resolves #12751

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Nov 17, 2022
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
@HertzDevil
Copy link
Contributor

as? alone has never acted as a type filter:

x = 1 || ""
if x.as?(String)
  x.codepoints # Error: undefined method 'codepoints' for Int32 (compile-time type is (Int32 | String))
end

Assignment to a separate variable is necessary here.

@straight-shoota
Copy link
Member Author

Yes, that's what the spec is supposed to do. Seems to have ended up differently when I refactored it before publishing the PR, and the edit suggestions didn't help either 🙈

Correct example is in #12751

Fixed it now.

@straight-shoota straight-shoota added this to the 1.7.0 milestone Nov 22, 2022
@straight-shoota straight-shoota merged commit 33c1c2e into crystal-lang:master Nov 23, 2022
@straight-shoota straight-shoota deleted the fix/truthy-filter-merge branch November 23, 2022 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Truthy type filter merges resulting non-nil types
4 participants