Skip to content

Commit cf351a2

Browse files
committed
Disallow wildcard arguments in new
These might lead to bad bounds if unchecked. Scalac disallows them also, but with a confusing error message ("class type expected" on the class).
1 parent f532c9a commit cf351a2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
241241

242242
/** Would import of kind `prec` be not shadowed by a nested higher-precedence definition? */
243243
def isPossibleImport(prec: Int)(implicit ctx: Context) =
244-
!noImports &&
244+
!noImports &&
245245
(prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))
246246

247247
@tailrec def loop(implicit ctx: Context): Type = {
@@ -446,6 +446,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
446446
case _ =>
447447
}
448448
checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true)
449+
450+
tpt1 match {
451+
case AppliedTypeTree(_, targs) =>
452+
for (targ @ TypeBoundsTree(_, _) <- targs)
453+
ctx.error("type argument must be fully defined", targ.pos)
454+
case _ =>
455+
}
456+
449457
assignType(cpy.New(tree)(tpt1), tpt1)
450458
// todo in a later phase: checkInstantiatable(cls, tpt1.pos)
451459
}

tests/neg/i1643.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait T extends Array {
2+
def t1(as: String*): Array[String] = { varargs1(as: _*) } // error
3+
def t2(as: String*): Array[String] = { super.varargs1(as: _*) } // error
4+
}
5+
class C extends Base_1 { // error
6+
def c1(as: String*): Array[String] = { varargs1(as: _*) } // error
7+
def c2(as: String*): Array[String] = { super.varargs1(as: _*) } // error
8+
}
9+
object Test extends App {
10+
val t = new T {} // error
11+
println(t.t1("a", "b").mkString(","))
12+
println(t.t2("a", "b").mkString(","))
13+
val c = new C {}
14+
println(c.c1("a", "b").mkString(","))
15+
println(c.c2("a", "b").mkString(","))
16+
17+
class CC[T]
18+
val x = new CC[_] // error
19+
}

0 commit comments

Comments
 (0)