diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 172dacf242d9..f56c2675d282 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1500,8 +1500,9 @@ object desugar { // Desugar [T_1, ..., T_M] -> (P_1, ..., P_N) => R // Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R } - val applyVParams = vargs.zipWithIndex.map { case (p, n) => - makeSyntheticParameter(n + 1, p).withAddedFlags(mods.flags) + val applyVParams = vargs.zipWithIndex.map { + case (p: ValDef, _) => p.withAddedFlags(mods.flags) + case (p, n) => makeSyntheticParameter(n + 1, p).withAddedFlags(mods.flags) } RefinedTypeTree(polyFunctionTpt, List( DefDef(nme.apply, applyTParams, List(applyVParams), res, EmptyTree) diff --git a/tests/neg/i6891.scala b/tests/neg/i6891.scala new file mode 100644 index 000000000000..20361e22c044 --- /dev/null +++ b/tests/neg/i6891.scala @@ -0,0 +1,10 @@ +object Test { + trait Foo { type X } + class Bar extends Foo { type X = Int } + type F = [A <: Foo] => (f: A) => f.X => f.X + + def main(args: Array[String]): Unit = { + val g: F = [A <: Foo] => (f: A) => (x: f.X) => x + println(g(new Bar)("foo")) // error + } +} diff --git a/tests/pos/i6891.scala b/tests/pos/i6891.scala new file mode 100644 index 000000000000..8a4177a0107b --- /dev/null +++ b/tests/pos/i6891.scala @@ -0,0 +1 @@ +def foo(App: [A] => (f: A) => Any): Any = ??? diff --git a/tests/run/i6891.check b/tests/run/i6891.check new file mode 100644 index 000000000000..d00491fd7e5b --- /dev/null +++ b/tests/run/i6891.check @@ -0,0 +1 @@ +1 diff --git a/tests/run/i6891.scala b/tests/run/i6891.scala new file mode 100644 index 000000000000..5492b1337aa3 --- /dev/null +++ b/tests/run/i6891.scala @@ -0,0 +1,10 @@ +object Test { + trait Foo { type X } + class Bar extends Foo { type X = Int } + type F = [A <: Foo] => (f: A) => f.X => f.X + + def main(args: Array[String]): Unit = { + val g: F = [A <: Foo] => (f: A) => (x: f.X) => x + println(g(new Bar)(1)) + } +}