-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Make extractor patterns null safe #6485
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
Conversation
2dc5ec1 to
b6a007d
Compare
|
See also: https://github.com/scala/scala/pull/6485/files#diff-352de7f9c77a7e21df6940d6a1bcdc7eL115, where a type test is potentially emitted before an extractor call, which could also rule out null args. |
|
Note that Dotty already has the behavior implemented by this PR. |
| } else { | ||
| val nonNullTest = NonNullTestTreeMaker(typeTest.nextBinder, paramType, pos) | ||
| val unappBinder = nonNullTest.nextBinder | ||
| (typeTest :: nonNullTest :: treeMakers(unappBinder, pos), unappBinder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adriaanm Instead of doing null check in ExtractorTreeMaker (like I had in b6a007d), I've created a new tree maker NonNullTestTreeMaker. This is positioned after typeTest. If binderKnowNonNull is true, I am skipping the test.
I've removed null checking in ProductExtractorTreeMaker and passing binderKnowNonNull around since it's now redundant.
cee9f3a to
f08f7b5
Compare
|
Rebased and squashed. |
f08f7b5 to
df7fc06
Compare
df7fc06 to
1f0c8a7
Compare
|
Rebased and slightly reworded. |
Until now, the spec did not say anything about `null` for extractor pattern, so that: - The pattern matcher would happily pass `null` into your extractor. - One could write a `null`-matching extractor `MyNull`. - But all extractor authors must consider `null` as a possible argument value. No more! The pattern matcher inserts a non-`null` check before invoking an extractor, so that you don't have to. This is a general fix for scala/bug#2241, scala/bug#8787. See scala/bug#4364.
1f0c8a7 to
a60eaeb
Compare
| List((1,2),(3,4),(5,6)) == z | ||
| } | ||
|
|
||
| def run(): Unit = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated test for procedure syntax deprecation.
|
Ping |
|
LGTM -- checked diff for |
It turned out that scala extractor pattern doesn't handle null correctly. See scala/scala#6485. As a result the handling of null has to move from extractor into the main match block. The problem was not noticed earlier because the test for null encoding was missed.
Ref scala/bug#4364
This is a general fix for scala/bug#2241 and scala/bug#8787.
scala/bug#4364 raises the question of what should the pattern matcher do when encountering a
nulland an extractor pattern. As it stands, SLS does not say anything aboutnullfor extractor pattern, which leads:nullinto your extractor.null-matching extractor MyNull.nullif they would like to access the passed in argumentx.There are potentially two things we can do.
null.nullis treated as no match (empty).I've already sent option 1 as #6374.
This implements option 2.