Skip to content

Commit 6b33da7

Browse files
authored
Merge pull request #5634 from dotty-staging/fix-#5328
Fix #5328: Disallow repeated type application
2 parents 880eeac + 3568757 commit 6b33da7

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
881881
typedExpr(tree.fun, PolyProto(typedArgs, pt)) match {
882882
case ExtMethodApply(app) =>
883883
app
884+
case _: TypeApply if !ctx.isAfterTyper =>
885+
errorTree(tree, "illegal repeated type application")
884886
case typedFn =>
885887
typedFn.tpe.widen match {
886888
case pt: PolyType =>

tests/neg/i5328.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class C[X, Y] { def apply[Z](x: X, y: Y, z: Z) = (x, y, z) }
2+
3+
object Test {
4+
def f[X, Y]: C[X, Y] = new C[X, Y]
5+
f[Int, Boolean][String](1, true, "") // OK
6+
f[X = Int](1, true, "") // OK, Y and Z are inferred
7+
f[X = Int][String](1, true, "") // error: illegal repeated type application
8+
}

tests/neg/namedTypeParams.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ object Test {
1212
def f[X, Y](x: X, y: Y): Int = ???
1313

1414
f[X = Int, String](1, "") // error // error
15-
f[X = Int][X = Int][Y = String](1, "") // error
15+
f[X = Int][X = Int][Y = String](1, "") // error: illegal repeated type application
16+
17+
f[X = Int][Y = String](1, "") // error: illegal repeated type application
18+
f[X = Int][String](1, "") // error: illegal repeated type application
19+
20+
f[Y = String][X = Int](1, "") // error: illegal repeated type application
21+
f[Y = String][Int](1, "") // error: illegal repeated type application
1622
}

tests/pos/i5328.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class C[X, Y] { def apply[Z](x: X, y: Y, z: Z) = (x, y, z) }
2+
3+
object Test {
4+
def f[X, Y, Z]: C[X, Y] = new C[X, Y]
5+
f[Int, Boolean, Any][String](1, true, "") // OK
6+
f[X = Int](1, true, "") // OK, Y and Z are inferred
7+
f[Z = Any, X = Int](1, true, "") // OK
8+
}

tests/pos/namedTypeParams.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ object Test {
77
f[X = Int](1, "")
88
f[Y = String](1, "")
99

10-
f[X = Int][Y = String](1, "")
11-
f[X = Int][String](1, "")
1210

13-
f[Y = String][X = Int](1, "")
14-
f[Y = String][Int](1, "")
1511
}

0 commit comments

Comments
 (0)