Skip to content

Commit 3c5e4a0

Browse files
committed
minimize diff
1 parent 7f95284 commit 3c5e4a0

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ object PatternMatcher {
345345

346346
// Disable Scala2Unapply optimization if the argument is a named argument for a single-element named tuple to
347347
// enable selecting the field. See i23131.scala for test cases.
348-
val wasSingleNamedArgForNamedTuple =
348+
val wasUnaryNamedTupleSelectArgForNamedTuple =
349349
args.length == 1 && args.head.removeAttachment(FirstTransform.WasNamedArg).isDefined &&
350350
isGetMatch(unappType) && unapp.select(nme.get, _.info.isParameterless).tpe.widenDealias.isNamedTupleType
351-
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length && !wasSingleNamedArgForNamedTuple)
351+
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length && !wasUnaryNamedTupleSelectArgForNamedTuple)
352352
def tupleSel(sym: Symbol) =
353353
// If scrutinee is a named tuple, cast to underlying tuple, so that we can
354354
// continue to select with _1, _2, ...
@@ -397,10 +397,11 @@ object PatternMatcher {
397397
// NamedArg trees are eliminated in FirstTransform but for named arguments
398398
// of patterns we add a WasNamedArg attachment, which is used to guide the
399399
// logic here. See i22900.scala for test cases.
400-
val selectors = if args.length == 1 && !wasSingleNamedArgForNamedTuple then
401-
ref(getResult) :: Nil
402-
else
403-
productSelectors(getResult.info).map(ref(getResult).select(_))
400+
val selectors = args match
401+
case arg :: Nil if !wasUnaryNamedTupleSelectArgForNamedTuple =>
402+
ref(getResult) :: Nil
403+
case _ =>
404+
productSelectors(getResult.info).map(ref(getResult).select(_))
404405
matchArgsPlan(selectors, args, onSuccess)
405406
}
406407
}

tests/run/i23131.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@ import scala.NamedTuple
33
def Test =
44
Some((name = "Bob")) match {
55
case Some(name = a) => println(a)
6-
}
7-
// (name = "Bob") match { // works fine
8-
// case (name = a) => println (a)
9-
// }
6+
}

0 commit comments

Comments
 (0)