Skip to content

Commit 2e88456

Browse files
committed
Refine unapply case accessor condition
1 parent b5f7cfb commit 2e88456

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ object PatternMatcher {
327327
/** Plan for matching the result of an unapply against argument patterns `args` */
328328
def unapplyPlan(unapp: Tree, args: List[Tree]): Plan = {
329329
def caseClass = unapp.symbol.owner.linkedClass
330-
lazy val caseAccessors = caseClass.caseAccessors.filter(sym => sym.is(Method) || sym.owner.is(Scala2Tasty))
330+
lazy val scala2CaseAccessors =
331+
if caseClass.is(Scala2Tasty) then caseClass.caseAccessors
332+
else caseClass.caseAccessors.filter(_.is(Method))
331333

332334
def isSyntheticScala2Unapply(sym: Symbol) =
333335
sym.isAllOf(SyntheticCase) && sym.owner.is(Scala2x)
@@ -337,11 +339,11 @@ object PatternMatcher {
337339
.select(defn.RuntimeTuples_apply)
338340
.appliedTo(receiver, Literal(Constant(i)))
339341

340-
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
342+
if (isSyntheticScala2Unapply(unapp.symbol) && scala2CaseAccessors.length == args.length)
341343
def tupleSel(sym: Symbol) = ref(scrutinee).select(sym)
342344
val isGenericTuple = defn.isTupleClass(caseClass) &&
343345
!defn.isTupleNType(tree.tpe match { case tp: OrType => tp.join case tp => tp }) // widen even hard unions, to see if it's a union of tuples
344-
val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp(_, ref(scrutinee))) else caseAccessors.map(tupleSel)
346+
val components = if isGenericTuple then scala2CaseAccessors.indices.toList.map(tupleApp(_, ref(scrutinee))) else scala2CaseAccessors.map(tupleSel)
345347
matchArgsPlan(components, args, onSuccess)
346348
else if (unapp.tpe <:< (defn.BooleanType))
347349
TestPlan(GuardTest, unapp, unapp.span, onSuccess)

0 commit comments

Comments
 (0)