From f532c9acb9aef9a93f52109c320ea5c944de46bc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 5 Nov 2016 15:43:53 +0100 Subject: Fix #1643: Avoid crash due to previous errors We assumed that argument types in an untpd.New are never wildcards but in the face of errors that is not true. --- src/dotty/tools/dotc/ast/untpd.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala index ac3beaff4..f259bdc57 100644 --- a/src/dotty/tools/dotc/ast/untpd.scala +++ b/src/dotty/tools/dotc/ast/untpd.scala @@ -282,7 +282,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { case TypedSplice(AppliedTypeTree(tycon, targs)) => (TypedSplice(tycon), targs map (TypedSplice(_))) case TypedSplice(tpt1: Tree) => - val argTypes = tpt1.tpe.argTypes + val argTypes = tpt1.tpe.argTypesLo val tycon = tpt1.tpe.withoutArgs(argTypes) def wrap(tpe: Type) = TypeTree(tpe) withPos tpt.pos (wrap(tycon), argTypes map wrap) -- cgit v1.2.3 From cf351a20fcd9de79eedeca76fad59bad55d5a5ec Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 5 Nov 2016 15:45:03 +0100 Subject: 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). --- src/dotty/tools/dotc/typer/Typer.scala | 10 +++++++++- tests/neg/i1643.scala | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i1643.scala (limited to 'src') diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 899b857ae..95f0c5614 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -241,7 +241,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit /** Would import of kind `prec` be not shadowed by a nested higher-precedence definition? */ def isPossibleImport(prec: Int)(implicit ctx: Context) = - !noImports && + !noImports && (prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope)) @tailrec def loop(implicit ctx: Context): Type = { @@ -446,6 +446,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case _ => } checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) + + tpt1 match { + case AppliedTypeTree(_, targs) => + for (targ @ TypeBoundsTree(_, _) <- targs) + ctx.error("type argument must be fully defined", targ.pos) + case _ => + } + assignType(cpy.New(tree)(tpt1), tpt1) // todo in a later phase: checkInstantiatable(cls, tpt1.pos) } diff --git a/tests/neg/i1643.scala b/tests/neg/i1643.scala new file mode 100644 index 000000000..d836a4255 --- /dev/null +++ b/tests/neg/i1643.scala @@ -0,0 +1,19 @@ +trait T extends Array { + def t1(as: String*): Array[String] = { varargs1(as: _*) } // error + def t2(as: String*): Array[String] = { super.varargs1(as: _*) } // error +} +class C extends Base_1 { // error + def c1(as: String*): Array[String] = { varargs1(as: _*) } // error + def c2(as: String*): Array[String] = { super.varargs1(as: _*) } // error +} +object Test extends App { + val t = new T {} // error + println(t.t1("a", "b").mkString(",")) + println(t.t2("a", "b").mkString(",")) + val c = new C {} + println(c.c1("a", "b").mkString(",")) + println(c.c2("a", "b").mkString(",")) + + class CC[T] + val x = new CC[_] // error +} -- cgit v1.2.3