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

allow nullability flow typing even in presence of pattern match #18206

Merged
merged 2 commits into from
Oct 1, 2023

Conversation

olhotak
Copy link
Contributor

@olhotak olhotak commented Jul 14, 2023

Nullability flow typing is conservatively disabled for mutable variables to which a write occurs nested inside a Tree other than some known ones, such as If and WhileDo. This is to prevent flow-sensitive reasoning for variables that are captured and written to in a closure. Pattern matches do not create a closure. This change enables nullability flow typing even for mutable variables that are written to inside a pattern match.

@olhotak olhotak self-assigned this Jul 14, 2023
@olhotak olhotak requested review from odersky and noti0na1 July 14, 2023 01:09
@olhotak olhotak force-pushed the fix-match-flow-typing branch from bae1d8f to f0b9af5 Compare July 17, 2023 21:09
@noti0na1
Copy link
Member

I'd like test this PR after #18212 is merged.

var s: String | Null = ???

s match 
  case null => s = ""
  case _ =>

val ss: String = s

Will this work?

Nullability flow typing is conservatively disabled for mutable
variables to which a write occurs nested inside a Tree other than
some known ones, such as If and WhileDo. This is to prevent flow-sensitive
reasoning for variables that are captured and written to in a closure.
Pattern matches do not create a closure. This change enables nullability
flow typing even for mutable variables that are written to inside a pattern
match.
@olhotak olhotak force-pushed the fix-match-flow-typing branch from f0b9af5 to f351ec4 Compare July 21, 2023 18:47
@olhotak
Copy link
Contributor Author

olhotak commented Jul 23, 2023

It should be possible to also do this for Try, at least for the try and catch, though I'm not sure about the finally.

@odersky odersky merged commit 5c47c5e into scala:main Oct 1, 2023
@odersky odersky deleted the fix-match-flow-typing branch October 1, 2023 15:23
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
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.

4 participants