Skip to content

Commit 278f7f4

Browse files
Merge pull request #6917 from dotty-staging/i6891
Fix #6891: Assertion failed when naming parameter in polymorphic function type
2 parents 0c1f78d + 2bc3c97 commit 278f7f4

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,9 @@ object desugar {
15001500
// Desugar [T_1, ..., T_M] -> (P_1, ..., P_N) => R
15011501
// Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R }
15021502

1503-
val applyVParams = vargs.zipWithIndex.map { case (p, n) =>
1504-
makeSyntheticParameter(n + 1, p).withAddedFlags(mods.flags)
1503+
val applyVParams = vargs.zipWithIndex.map {
1504+
case (p: ValDef, _) => p.withAddedFlags(mods.flags)
1505+
case (p, n) => makeSyntheticParameter(n + 1, p).withAddedFlags(mods.flags)
15051506
}
15061507
RefinedTypeTree(polyFunctionTpt, List(
15071508
DefDef(nme.apply, applyTParams, List(applyVParams), res, EmptyTree)

tests/neg/i6891.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Test {
2+
trait Foo { type X }
3+
class Bar extends Foo { type X = Int }
4+
type F = [A <: Foo] => (f: A) => f.X => f.X
5+
6+
def main(args: Array[String]): Unit = {
7+
val g: F = [A <: Foo] => (f: A) => (x: f.X) => x
8+
println(g(new Bar)("foo")) // error
9+
}
10+
}

tests/pos/i6891.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def foo(App: [A] => (f: A) => Any): Any = ???

tests/run/i6891.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tests/run/i6891.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Test {
2+
trait Foo { type X }
3+
class Bar extends Foo { type X = Int }
4+
type F = [A <: Foo] => (f: A) => f.X => f.X
5+
6+
def main(args: Array[String]): Unit = {
7+
val g: F = [A <: Foo] => (f: A) => (x: f.X) => x
8+
println(g(new Bar)(1))
9+
}
10+
}

0 commit comments

Comments
 (0)