Skip to content

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 noti0na1 and odersky 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

4 participants