Skip to content

Commit

Permalink
Refine handling of pattern binders for large tuples (#19085)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky authored Nov 27, 2023
2 parents e7f8a2c + 21be611 commit 5ebeb7b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// wrt to operand order for `&`, we include the explicit subtype test here.
// See also #5649.
then body1.tpe
else pt & body1.tpe
else body1.tpe match
case btpe: TypeRef
if btpe.symbol == defn.TupleXXLClass && pt.tupleElementTypes.isDefined =>
// leave the original tuple type; don't mix with & TupleXXL which would only obscure things
pt
case _ =>
pt & body1.tpe
val sym = newPatternBoundSymbol(name, symTp, tree.span)
if (pt == defn.ImplicitScrutineeTypeRef || tree.mods.is(Given)) sym.setFlag(Given)
if (ctx.mode.is(Mode.InPatternAlternative))
Expand Down

0 comments on commit 5ebeb7b

Please sign in to comment.