Skip to content

Commit e2b5229

Browse files
Fix untupling of functions in for comprehensions
1 parent 5c628d9 commit e2b5229

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,15 +1621,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16211621
case untpd.Annotated(scrut1, _) => isParamRef(scrut1)
16221622
case untpd.Ident(id) => id == params.head.name
16231623
fnBody match
1624-
case untpd.Match(scrut, untpd.CaseDef(untpd.Tuple(elems), untpd.EmptyTree, rhs) :: Nil)
1624+
case untpd.Match(scrut, cases @ untpd.CaseDef(untpd.Tuple(elems), untpd.EmptyTree, rhs) :: Nil)
16251625
if scrut.span.isSynthetic && isParamRef(scrut) && elems.hasSameLengthAs(protoFormals) =>
16261626
// If `pt` is N-ary function type, convert synthetic lambda
16271627
// x$1 => x$1 match case (a1, ..., aN) => e
16281628
// to
16291629
// (a1, ..., aN) => e
16301630
val params1 = desugar.patternsToParams(elems)
1631-
if params1.hasSameLengthAs(elems) then
1632-
desugared = cpy.Function(tree)(params1, rhs)
1631+
desugared = if params1.hasSameLengthAs(elems)
1632+
then cpy.Function(tree)(params1, rhs)
1633+
else desugar.makeCaseLambda(cases, desugar.MatchCheck.IrrefutablePatDef, protoFormals.length)
16331634
case _ =>
16341635

16351636
if desugared.isEmpty then

tests/pos/i19576.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
object Test:
3+
val z = Seq(0 -> 1, 2 -> 3).lazyZip(Seq("A", "B"))
4+
for case ((beg, end), c) <- z yield c // Ok: a withFilter is inserted before map
5+
for (range, c) <- z yield c // Ok: exact shape
6+
for ((beg, end), c) <- z yield c // Error before changes: Wrong number of parameters, expected 2

0 commit comments

Comments
 (0)