Skip to content

Check for mismatched argument type length in PatternMatcher due to Named Tuple :* syntax #23602

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,14 @@ object PatternMatcher {
def matchArgsPatternPlan(args: List[Tree], syms: List[Symbol]): Plan =
args match {
case arg :: args1 =>
val sym :: syms1 = syms: @unchecked
patternPlan(sym, arg, matchArgsPatternPlan(args1, syms1))
if (args.length != syms.length)
report.error(UnapplyInvalidNumberOfArguments(tree, tree.tpe :: Nil), arg.srcPos)
// Generate a throwaway but type-correct plan.
// This plan will never execute because it'll be guarded by a `NonNullTest`.
ResultPlan(tpd.Throw(tpd.nullLiteral))
else
val sym :: syms1 = syms: @unchecked
patternPlan(sym, arg, matchArgsPatternPlan(args1, syms1))
case Nil =>
assert(syms.isEmpty)
onSuccess
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i23155a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.NamedTuple
object Unpack_NT {
(1, 2) match {
case Unpack_NT(first, _) => first // error
}
def unapply(e: (Int, Int)): Some[NamedTuple.NamedTuple["x" *: "y" *: EmptyTuple, Int *: Int *: EmptyTuple]] = ???
}
6 changes: 6 additions & 0 deletions tests/neg/i23155b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Unpack_T {
(1, 2) match {
case Unpack_T(first, _) => first // error
}
def unapply(e: (Int, Int)): Some[Int *: Int *: EmptyTuple] = ???
}
Loading