Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix untupling of functions in for comprehensions #19620

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1621,15 +1621,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case untpd.Annotated(scrut1, _) => isParamRef(scrut1)
case untpd.Ident(id) => id == params.head.name
fnBody match
case untpd.Match(scrut, untpd.CaseDef(untpd.Tuple(elems), untpd.EmptyTree, rhs) :: Nil)
case untpd.Match(scrut, cases @ untpd.CaseDef(untpd.Tuple(elems), untpd.EmptyTree, rhs) :: Nil)
if scrut.span.isSynthetic && isParamRef(scrut) && elems.hasSameLengthAs(protoFormals) =>
// If `pt` is N-ary function type, convert synthetic lambda
// x$1 => x$1 match case (a1, ..., aN) => e
// to
// (a1, ..., aN) => e
val params1 = desugar.patternsToParams(elems)
if params1.hasSameLengthAs(elems) then
desugared = cpy.Function(tree)(params1, rhs)
desugared = if params1.hasSameLengthAs(elems)
then cpy.Function(tree)(params1, rhs)
else desugar.makeCaseLambda(cases, desugar.MatchCheck.IrrefutablePatDef, protoFormals.length)
case _ =>

if desugared.isEmpty then
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i19576.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

object Test:
val z = Seq(0 -> 1, 2 -> 3).lazyZip(Seq("A", "B"))
for case ((beg, end), c) <- z yield c // Ok: a withFilter is inserted before map
for (range, c) <- z yield c // Ok: exact shape
for ((beg, end), c) <- z yield c // Error before changes: Wrong number of parameters, expected 2