diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index dd3e6f2ee8ca..fbdbd3df5580 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3961,10 +3961,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer else tree else if tree.tpe.derivesFrom(defn.PairClass) && !defn.isTupleNType(tree.tpe.widenDealias) then // If this is a generic tuple we need to cast it to make the TupleN/ members accessible. - // This only works for generic tuples of know size up to 22. - defn.tupleTypes(tree.tpe.widenTermRefExpr, Definitions.MaxTupleArity) match - case Some(elems) => tree.cast(defn.tupleType(elems)) - case None => tree + // This works only for generic tuples of known size up to 22. + defn.tupleTypes(tree.tpe.widenTermRefExpr) match + case Some(elems) if elems.length <= Definitions.MaxTupleArity => + tree.cast(defn.tupleType(elems)) + case _ => tree else tree // other adaptations for selections are handled in typedSelect case _ if ctx.mode.is(Mode.ImplicitsEnabled) && tree.tpe.isValueType => if pt.isRef(defn.AnyValClass, skipRefined = false) diff --git a/tests/pos/i16104.scala b/tests/pos/i16104.scala new file mode 100644 index 000000000000..7624d5c68a4a --- /dev/null +++ b/tests/pos/i16104.scala @@ -0,0 +1,18 @@ +trait JsonVal + +val value = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "k", "l", "m", "n", "o", "p", "q") +val tree: JsonVal = ??? + +def Case2 = { + sealed trait Write[T] + object WriteOf: + final inline def tuple[T <: Tuple]: Write[T] = ??? + + given EntryToJson[T]: scala.Conversion[T, JsonStructureEntry[T]] = ??? + class JsonStructureEntry[T](t: T): + def writeAs[X >: T](using Write[X]): util.Try[JsonVal] = ??? + + value + .writeAs(using WriteOf.tuple[String *: String *: String *: String *: String *: String *: String *: String *: String *: String *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: String *: String *: String *: String *: String *: String *: String *: EmptyTuple]) + .fold(_ => ???, _ == tree) +} \ No newline at end of file