Skip to content

Commit 5ebeb7b

Browse files
authored
Refine handling of pattern binders for large tuples (#19085)
Extracted from the named tuples PR, where it allowed the correct typing of ```scala val bob = ( x0 = 0, x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0, x7 = 0, x8 = 0, x9 = 0, name = "Bob", y1 = 0, age = 33, y2 = 0, z0 = 0, z1 = 0, z2 = 0, z3 = 0, z4 = 0, z5 = 0, z6 = 0, z7 = 0, z8 = 0, z9 = 0) bob match case p @ (name = "Bob", age = a) => p,age ``` The problem was that `p` was typed before as `<some large tuple type> & TupleXXL` and that prevented the correct analysis of tuple elements. I am submitting this as a separate PR since it might also be relevant for #19084.
2 parents e7f8a2c + 21be611 commit 5ebeb7b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
24342434
// wrt to operand order for `&`, we include the explicit subtype test here.
24352435
// See also #5649.
24362436
then body1.tpe
2437-
else pt & body1.tpe
2437+
else body1.tpe match
2438+
case btpe: TypeRef
2439+
if btpe.symbol == defn.TupleXXLClass && pt.tupleElementTypes.isDefined =>
2440+
// leave the original tuple type; don't mix with & TupleXXL which would only obscure things
2441+
pt
2442+
case _ =>
2443+
pt & body1.tpe
24382444
val sym = newPatternBoundSymbol(name, symTp, tree.span)
24392445
if (pt == defn.ImplicitScrutineeTypeRef || tree.mods.is(Given)) sym.setFlag(Given)
24402446
if (ctx.mode.is(Mode.InPatternAlternative))

0 commit comments

Comments
 (0)