Fix named-tuple pattern resolution under -Yexplicit-nulls#26233
Open
HarrisL2 wants to merge 1 commit into
Open
Fix named-tuple pattern resolution under -Yexplicit-nulls#26233HarrisL2 wants to merge 1 commit into
HarrisL2 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue minimized from a run of the open community build with explicit nulls enabled by default from #25461
A named-tuple pattern fails to compile under -Yexplicit-nulls when the scrutinee comes from a Java-defined generic (e.g. java.util.stream.Stream), even though the identical code compiles without the flag. This PR strips nullability from the expected type before desugaring such patterns, scoped to named-tuple patterns only.
Reproduction
Run with
scalac Test.scala -Yexplicit-nullsFix
In
Typer.typedTuple, strip nullability from the expected type before desugaring, but only for patterns that actually carry named elements:I had a back and forth with the LLM for a justification:
Why unwrapping is sound
The change makes a
local pt = pt0.stripNull()insidetypedTuple, used only to desugar/type the pattern's sub-trees. A tuple pattern lowers to an unapply guarded by a non-null test:So the bindings (
sr) only ever run on non-null values.How much have you relied on LLM-based tools in this contribution?
Moderately, for generating a fix and the explanation
How was the solution tested?
New automated tests