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

Don't compute type filters inside typeof's argument #10739

Merged

Conversation

HertzDevil
Copy link
Contributor

The compiler currently computes type filters for expressions inside a typeof node's argument. However, not only do (top-level) conditionals inside typeof have no effect on the typeof itself's type, the variables inside may not even exist outside the node. For example:

if typeof(x = 1) # => Missing hash key: "x" (KeyError)
end

A less obvious example is the following, where || internally expands to if expressions:

typeof(1 || 'x') || "" # => Missing hash key: "__temp_499" (KeyError)

This PR ensures typeof's argument does not request any type filters.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels May 21, 2021
@straight-shoota straight-shoota added this to the 1.1.0 milestone May 25, 2021
@straight-shoota straight-shoota merged commit 4dd04eb into crystal-lang:master May 28, 2021
@HertzDevil HertzDevil deleted the bug/typeof-cond-filter branch May 28, 2021 19:38
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.

3 participants