Skip to content

Commit e96d460

Browse files
committed
Fix definition of isGenericTuple by force-widening hard unions
1 parent 63144a0 commit e96d460

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,12 @@ object PatternMatcher {
337337

338338
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
339339
def tupleSel(sym: Symbol) = ref(scrutinee).select(sym)
340-
val isGenericTuple = defn.isTupleClass(caseClass) && !defn.isTupleNType(tree.tpe)
340+
val isGenericTuple = defn.isTupleClass(caseClass) && {
341+
val tp = tree.tpe match // widen even hard unions, to see if it's a union of tuples
342+
case tp @ OrType(l, r) => (if tp.isSoft then tp else tp.derivedOrType(l, r, soft = true)).widenUnion
343+
case tp => tp
344+
!defn.isTupleNType(tp)
345+
}
341346
val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp(tree.tpe.dealias, _, ref(scrutinee))) else caseAccessors.map(tupleSel)
342347
matchArgsPlan(components, args, onSuccess)
343348
else if (unapp.tpe <:< (defn.BooleanType))

0 commit comments

Comments
 (0)