Skip to content

Commit b66650b

Browse files
committed
Adapt generic tuples to be able to access members
Fixes #14215
1 parent ec43a19 commit b66650b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,6 +3854,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38543854
gadts.println(i"Member selection healed by GADT approximation")
38553855
tree.cast(gadtApprox)
38563856
else tree
3857+
else if tree.tpe.derivesFrom(defn.PairClass) && !defn.isTupleNType(tree.tpe.widenDealias) then
3858+
// If this is a generic tuple we need to cast it to make the TupleN/ members accessible.
3859+
// This only works for generic tuples of know size up to 22.
3860+
defn.tupleTypes(tree.tpe.widenTermRefExpr, Definitions.MaxTupleArity) match
3861+
case Some(elems) => tree.cast(defn.tupleType(elems))
3862+
case None => tree
38573863
else tree // other adaptations for selections are handled in typedSelect
38583864
case _ if ctx.mode.is(Mode.ImplicitsEnabled) && tree.tpe.isValueType =>
38593865
checkConversionsSpecific(pt, tree.srcPos)

0 commit comments

Comments
 (0)