diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 9c7d5c36942d..6e72c0e72e3e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -881,6 +881,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => typedExpr(tree.fun, PolyProto(typedArgs, pt)) match { case ExtMethodApply(app) => app + case _: TypeApply if !ctx.isAfterTyper => + errorTree(tree, "illegal repeated type application") case typedFn => typedFn.tpe.widen match { case pt: PolyType => diff --git a/tests/neg/i5328.scala b/tests/neg/i5328.scala new file mode 100644 index 000000000000..14e2cab5115d --- /dev/null +++ b/tests/neg/i5328.scala @@ -0,0 +1,8 @@ +class C[X, Y] { def apply[Z](x: X, y: Y, z: Z) = (x, y, z) } + +object Test { + def f[X, Y]: C[X, Y] = new C[X, Y] + f[Int, Boolean][String](1, true, "") // OK + f[X = Int](1, true, "") // OK, Y and Z are inferred + f[X = Int][String](1, true, "") // error: illegal repeated type application +} \ No newline at end of file diff --git a/tests/neg/namedTypeParams.scala b/tests/neg/namedTypeParams.scala index 80cfae87f077..6284926dc9d8 100644 --- a/tests/neg/namedTypeParams.scala +++ b/tests/neg/namedTypeParams.scala @@ -12,5 +12,11 @@ object Test { def f[X, Y](x: X, y: Y): Int = ??? f[X = Int, String](1, "") // error // error - f[X = Int][X = Int][Y = String](1, "") // error + f[X = Int][X = Int][Y = String](1, "") // error: illegal repeated type application + + f[X = Int][Y = String](1, "") // error: illegal repeated type application + f[X = Int][String](1, "") // error: illegal repeated type application + + f[Y = String][X = Int](1, "") // error: illegal repeated type application + f[Y = String][Int](1, "") // error: illegal repeated type application } diff --git a/tests/pos/i5328.scala b/tests/pos/i5328.scala new file mode 100644 index 000000000000..9f3fabb2b5f0 --- /dev/null +++ b/tests/pos/i5328.scala @@ -0,0 +1,8 @@ +class C[X, Y] { def apply[Z](x: X, y: Y, z: Z) = (x, y, z) } + +object Test { + def f[X, Y, Z]: C[X, Y] = new C[X, Y] + f[Int, Boolean, Any][String](1, true, "") // OK + f[X = Int](1, true, "") // OK, Y and Z are inferred + f[Z = Any, X = Int](1, true, "") // OK +} \ No newline at end of file diff --git a/tests/pos/namedTypeParams.scala b/tests/pos/namedTypeParams.scala index 2938b6dbd29b..d4088296bb8a 100644 --- a/tests/pos/namedTypeParams.scala +++ b/tests/pos/namedTypeParams.scala @@ -7,9 +7,5 @@ object Test { f[X = Int](1, "") f[Y = String](1, "") - f[X = Int][Y = String](1, "") - f[X = Int][String](1, "") - f[Y = String][X = Int](1, "") - f[Y = String][Int](1, "") }