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

Accept pointer instance types on falsey conditional branches #10464

Merged
merged 1 commit into from
Mar 19, 2021

Conversation

HertzDevil
Copy link
Contributor

Crystal currently only allows Bool and Nil when performing flow typing on a falsey variable, but all Pointer instances can also be falsey. This leads to the following bug:

x = false || Pointer(Void).null if true # => Pointer(Void).null
typeof(x)                               # => (Bool | Pointer(Void) | Nil)

if !x
  typeof(x) # => (Bool | Nil)
  p x       # Invalid memory access (signal 11) at address 0xb4
end

This PR adds all Pointer instance types to those falsey branches, so that the inner typeof will report the same type as the outer one.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Mar 2, 2021
Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

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

Thank you @HertzDevil 🙏

@straight-shoota straight-shoota added this to the 1.0.0 milestone Mar 17, 2021
@bcardiff bcardiff requested a review from asterite March 19, 2021 14:41
@bcardiff bcardiff merged commit f991977 into crystal-lang:master Mar 19, 2021
@HertzDevil HertzDevil deleted the bug/falsey-pointer branch March 20, 2021 07:39
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.

4 participants