Skip to content

Commit 29cf778

Browse files
committed
I give up on casting to the right type, it isn't necessary anyways
1 parent 83e0288 commit 29cf778

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,16 @@ object PatternMatcher {
329329
def isSyntheticScala2Unapply(sym: Symbol) =
330330
sym.isAllOf(SyntheticCase) && sym.owner.is(Scala2x)
331331

332-
def tupleApp(tuple: Type, i: Int, receiver: Tree) = // manually inlining the call to NonEmptyTuple#apply, because it's an inline method
332+
def tupleApp(i: Int, receiver: Tree) = // manually inlining the call to NonEmptyTuple#apply, because it's an inline method
333333
ref(defn.RuntimeTuplesModule)
334334
.select(defn.RuntimeTuples_apply)
335335
.appliedTo(receiver, Literal(Constant(i)))
336-
.cast(tuple.tupleElementTypes.applyOrElse(i, (_: Int) => NoType).ensuring(_ != NoType, i"Failed to find type at index $i in $tuple (${tree.sourcePos})"))
337336

338337
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
339338
def tupleSel(sym: Symbol) = ref(scrutinee).select(sym)
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-
}
346-
val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp(tree.tpe.dealias, _, ref(scrutinee))) else caseAccessors.map(tupleSel)
339+
val isGenericTuple = defn.isTupleClass(caseClass) &&
340+
!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
341+
val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp(_, ref(scrutinee))) else caseAccessors.map(tupleSel)
347342
matchArgsPlan(components, args, onSuccess)
348343
else if (unapp.tpe <:< (defn.BooleanType))
349344
TestPlan(GuardTest, unapp, unapp.span, onSuccess)
@@ -363,7 +358,7 @@ object PatternMatcher {
363358
unapplySeqPlan(unappResult, args)
364359
}
365360
else if unappResult.info <:< defn.NonEmptyTupleTypeRef then
366-
val components = (0 until foldApplyTupleType(unappResult.denot.info).length).toList.map(tupleApp(unappResult.info, _, ref(unappResult)))
361+
val components = (0 until foldApplyTupleType(unappResult.denot.info).length).toList.map(tupleApp(_, ref(unappResult)))
367362
matchArgsPlan(components, args, onSuccess)
368363
else {
369364
assert(isGetMatch(unapp.tpe))

0 commit comments

Comments
 (0)