Skip to content

Commit 7813fe9

Browse files
committed
Found TypeUtils tupleElementTypes, which is right
1 parent 2584ffe commit 7813fe9

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Symbols._, Contexts._, Types._, StdNames._, NameOps._
99
import util.Spans._
1010
import typer.Applications.*
1111
import SymUtils._
12+
import TypeUtils.*
1213
import Flags._, Constants._
1314
import Decorators._
1415
import NameKinds.{PatMatStdBinderName, PatMatAltsName, PatMatResultName}
@@ -332,7 +333,7 @@ object PatternMatcher {
332333
ref(defn.RuntimeTuplesModule)
333334
.select(defn.RuntimeTuples_apply)
334335
.appliedTo(receiver, Literal(Constant(i)))
335-
.cast(indexTupleType(tuple, i).ensuring(_ != NoType, i"Failed to find type at index $i in $tuple"))
336+
.cast(tuple.tupleElementTypes.applyOrElse(i, (_: Int) => NoType).ensuring(_ != NoType, i"Failed to find type at index $i in $tuple (${tree.sourcePos})"))
336337

337338
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
338339
def tupleSel(sym: Symbol) = ref(scrutinee).select(sym)

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ object Applications {
207207
end tupleFold
208208
tupleFold(Nil, tp).reverse
209209

210-
/** The component type of a generic tuple at index `idx`. For example, `indexTupleType(A *: B *: EmptyTuple, 1) = B`. */
211-
def indexTupleType(tp: Type, idx: Int)(using Context): Type = tp.widen match
212-
case AppliedType(tycon, List(l, r)) if tycon.typeSymbol == defn.PairClass => if idx == 0 then l else indexTupleType(r, idx - 1)
213-
case t => NoType
214-
215210
def wrapDefs(defs: mutable.ListBuffer[Tree], tree: Tree)(using Context): Tree =
216211
if (defs != null && defs.nonEmpty) tpd.Block(defs.toList, tree) else tree
217212

0 commit comments

Comments
 (0)