Skip to content

Fix #5328: Disallow repeated type application #5634

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

Merged
merged 3 commits into from
Dec 17, 2018
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i5328.scala
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 7 additions & 1 deletion tests/neg/namedTypeParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions tests/pos/i5328.scala
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 0 additions & 4 deletions tests/pos/namedTypeParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}