Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ object PatternMatcher {
receiver.ensureConforms(defn.NonEmptyTupleTypeRef), // If scrutinee is a named tuple, cast to underlying tuple
Literal(Constant(i)))

if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
val wasNamedArg = args.length == 1 && args.head.removeAttachment(FirstTransform.WasNamedArg).isDefined
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length && !wasNamedArg)
def tupleSel(sym: Symbol) =
// If scrutinee is a named tuple, cast to underlying tuple, so that we can
// continue to select with _1, _2, ...
Expand Down Expand Up @@ -388,7 +389,7 @@ object PatternMatcher {
letAbstract(get) { getResult =>
def isUnaryNamedTupleSelectArg(arg: Tree) =
get.tpe.widenDealias.isNamedTupleType
&& arg.removeAttachment(FirstTransform.WasNamedArg).isDefined
&& wasNamedArg
// Special case: Normally, we pull out the argument wholesale if
// there is only one. But if the argument is a named argument for
// a single-element named tuple, we have to select the field instead.
Expand Down
9 changes: 9 additions & 0 deletions tests/run/i23131.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.NamedTuple
@main
def Test =
Some((name = "Bob")) match {
case Some(name = a) => println(a)
}
// (name = "Bob") match { // works fine
// case (name = a) => println (a)
// }
Loading