Check for mismatched argument type length in PatternMatcher due to Named Tuple :* syntax #23602
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.
Fixes #23155
After discussing at the compiler meeting, it was decided that the Named Tuple behavior should be the same as the Tuple behavior with respect to pattern matching with the
:*
syntax. To error in the exact same way, it should be caught here:scala3/compiler/src/dotty/tools/dotc/typer/Applications.scala
Line 291 in 00d19df
For regular tuples,
argTypes
is anAppliedType
of:*
and is not yet reduced, so has length 1, so the arity check will fail. However, at this point Named Tuple types are fully reduced bytupleElementTypes
here:scala3/compiler/src/dotty/tools/dotc/typer/Applications.scala
Line 249 in 00d19df
So for Named Tuples,
argTypes
at the time of the check will be(Int, Int)
so the arity check will pass, causing a later crash in PatternMatcher here:scala3/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Line 270 in 6146b90
We cannot un-reduce or fail to reduce for Named Tuple types because it will cause a host of other tests to fail that rely on the fully reduced Named Tuple-value types. For now I have added a check in PatternMatcher because it’s better to fix the compiler crash ASAP, but I think we could revisit if we want something like
Int :* Int :* EmptyTuple
to really behave differently from(Int, Int)
here, since pattern matching currently works for both Tuples and Named Tuples using(Int, Int)
orTuple2[Int, Int]
, just not:*
.