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

Use only last sub-expression of Expressions nodes for conditional type filters #10738

Merged
merged 2 commits into from
May 25, 2021

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented May 21, 2021

Fixes the following run-time error:

if (x = nil; true)
  p x # => can't execute `p(x)` at eval:2:3: `x` has no type (Exception)
end

This happens because Crystal computes the type filter from all sub-expressions of the (x = nil; true) node, and x = nil produces a truthy filter on x, even though the Nil type is never truthy; thus flow typing gives x no type inside the if-clause. This PR restricts the filter computation to the last sub-expression.

Similar errors can be triggered with while expressions; #10350 probably requires this PR.

@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
@asterite asterite merged commit a556e3c into crystal-lang:master May 25, 2021
@HertzDevil HertzDevil deleted the bug/expressions-cond-filter branch May 25, 2021 15:10
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