Skip to content

Commit 2183e53

Browse files
committed
Skip bypassing unapply for scala 2 case classes to allow for single-element named tuple in unapply
1 parent 00d19df commit 2183e53

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ object PatternMatcher {
343343
receiver.ensureConforms(defn.NonEmptyTupleTypeRef), // If scrutinee is a named tuple, cast to underlying tuple
344344
Literal(Constant(i)))
345345

346-
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
346+
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length && args.length != 1)
347347
def tupleSel(sym: Symbol) =
348348
// If scrutinee is a named tuple, cast to underlying tuple, so that we can
349349
// continue to select with _1, _2, ...

tests/run/i23131.scala

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

0 commit comments

Comments
 (0)