diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 80e4365a943c..663f4393ad67 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -311,11 +311,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { val (tycon, targs) = tpt match { case AppliedTypeTree(tycon, targs) => (tycon, targs) - case TypedSplice(AppliedTypeTree(tycon, targs)) => - (TypedSplice(tycon), targs map (TypedSplice(_))) case TypedSplice(tpt1: tpd.Tree) => - val tycon = tpt1.tpe.typeConstructor - val argTypes = tpt1.tpe.argTypesLo + val tp = tpt1.tpe.dealias + val tycon = tp.typeConstructor + val argTypes = tp.argTypesLo def wrap(tpe: Type) = TypeTree(tpe) withPos tpt.pos (wrap(tycon), argTypes map wrap) case _ => diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index da66c5b622b5..459555675f6d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -516,7 +516,8 @@ class Typer extends Namer case TypeApplications.EtaExpansion(tycon) => tpt1 = tpt1.withType(tycon) case _ => } - checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) + if (checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) eq defn.ObjectType) + tpt1 = TypeTree(defn.ObjectType).withPos(tpt1.pos) tpt1 match { case AppliedTypeTree(_, targs) => diff --git a/tests/neg/i4557.scala b/tests/neg/i4557.scala new file mode 100644 index 000000000000..14679657b35b --- /dev/null +++ b/tests/neg/i4557.scala @@ -0,0 +1,19 @@ +class C0[A] +class C1[A, B] + +object O { + type T0 = C0 + type T1 = C0[String, Int] // error + type T2[A] = C0[A, Int] // error + + type S0 = C1 + type S1 = C1[Int] // error + + class D0 extends T0 // error + class D1 extends T0[Int] + class D2 extends T0[String, Int] // error + + class E0 extends S0 // error + class E1 extends S0[Int] // error + class E2 extends S0[String, Int] +} diff --git a/tests/neg/i4557a.scala b/tests/neg/i4557a.scala new file mode 100644 index 000000000000..9cdec6a5391b --- /dev/null +++ b/tests/neg/i4557a.scala @@ -0,0 +1,6 @@ +class A[X] + +object T { + type Foo[X, Y] = [Z] => A[X] + class B extends Foo[Int, Int] // error +} diff --git a/tests/pos/i2104b.decompiled b/tests/pos/i2104b.decompiled index 00b2461d1e69..37893eea43f5 100644 --- a/tests/pos/i2104b.decompiled +++ b/tests/pos/i2104b.decompiled @@ -31,7 +31,7 @@ case class Pair[A, B](_1: A, _2: B) { throw new java.lang.IndexOutOfBoundsException(n.toString()) } } -object Pair extends scala.AnyRef() +object Pair /** Decompiled from out/posTestFromTasty/pos/i2104b/Test.class */ object Test { def main(args: scala.Array[scala.Predef.String]): scala.Unit = { diff --git a/tests/pos/i4557.scala b/tests/pos/i4557.scala new file mode 100644 index 000000000000..14b6dc4a254a --- /dev/null +++ b/tests/pos/i4557.scala @@ -0,0 +1,6 @@ +class Parser[T, Elem] + +object Test { + type P[T] = Parser[T, Char] + class CustomParser extends P[Unit] +} diff --git a/tests/pos/i4557a.scala b/tests/pos/i4557a.scala new file mode 100644 index 000000000000..14f09cdcfe1a --- /dev/null +++ b/tests/pos/i4557a.scala @@ -0,0 +1,6 @@ +class A[X] +object O { + type T[X, Y] = A[X] + type S[X, Y] = T[X, Y] + class B extends S[Int, Int] +} diff --git a/tests/pos/simpleCaseClass-3.decompiled b/tests/pos/simpleCaseClass-3.decompiled index 1dfef3b7f431..d2a3acf557ea 100644 --- a/tests/pos/simpleCaseClass-3.decompiled +++ b/tests/pos/simpleCaseClass-3.decompiled @@ -22,4 +22,4 @@ case class A[T](x: T) { throw new java.lang.IndexOutOfBoundsException(n.toString()) } } -object A extends scala.AnyRef() +object A diff --git a/tests/run/i4557.check b/tests/run/i4557.check new file mode 100644 index 000000000000..e9d2ea57b564 --- /dev/null +++ b/tests/run/i4557.check @@ -0,0 +1,28 @@ +c0 +c0 +c1 +0 +c1 +1 +c1 +2 +c1 +3 +c2 +0 +a +c2 +1 +b +c2 +2 +c +c2 +3 +d +c2 +4 +e +c2 +5 +f diff --git a/tests/run/i4557.scala b/tests/run/i4557.scala new file mode 100644 index 000000000000..8942e92a0113 --- /dev/null +++ b/tests/run/i4557.scala @@ -0,0 +1,71 @@ +trait F { + def f: Unit +} + +abstract class C0 extends F { + def f = println("c0") +} + +abstract class C1[A](val a: A) extends F { + def f = { + println("c1") + println(a) + } +} + +abstract class C2[A, B](val a: A, val b: B) extends F { + def f = { + println("c2") + println(a) + println(b) + } +} + +object Test { + type T0 = C0 + class DC0 extends C0 + class DT0 extends T0 + + type T1[T] = C1[T] + class DC1 extends C1[Int](0) + class DT1 extends T1[Int](1) + + type T11 = C1[Int] + class DT11 extends T11(2) + + type T12 = C1 + class DT12 extends T12[Int](3) + + type T2[T, S] = C2[T, S] + class DC2 extends C2[Int, String](0, "a") + class DT2 extends T2[Int, String](1, "b") + + type T21[T] = C2[T, String] + class DT21 extends T21[Int](2, "c") + + type T22 = C2[Int, String] + class DT22 extends T22(3, "d") + + type T23[T, S] = T2[T, S] + class DT23 extends T23(4, "e") + + type T24 = C2 + class DT24 extends T24[Int, String](5, "f") + + def main(args: Array[String]) = { + List( + new DC0, + new DT0, + new DC1, + new DT1, + new DT11, + new DT12, + new DC2, + new DT2, + new DT21, + new DT22, + new DT23, + new DT24 + ).foreach(_.f) + } +} diff --git a/tests/run/i4557a.check b/tests/run/i4557a.check new file mode 100644 index 000000000000..e84354dbb12b --- /dev/null +++ b/tests/run/i4557a.check @@ -0,0 +1,4 @@ +1 +a +2 +b diff --git a/tests/run/i4557a.scala b/tests/run/i4557a.scala new file mode 100644 index 000000000000..f1ecfab230b2 --- /dev/null +++ b/tests/run/i4557a.scala @@ -0,0 +1,24 @@ +abstract class C0[X, Y, Z, W](x: X, y: Y, z: Z, w: W) { + def f: Unit = { + println(x) + println(y) + println(z) + println(w) + } +} + +object Test { + type T0[X, Y, Z, A, B, C] = C0[X, Y, Z, A] + type T1[A, B, C, D] = T0[A, B, C, D, Nothing, Any] + type T2[E, F] = T1[E, F, E, F] + type T3[X, Y, Z] = T2[X, Z] + type T4[X, Y, Z, W] = T3[X, W, Y] + type T5[A, B] = T4[A, B, (Int, Int), Unit] + type T6 = T5[Int, String] + + class D extends T6(1, "a", 2, "b") + + def main(args: Array[String]) = { + (new D).f + } +} diff --git a/tests/run/valueclasses-pavlov.decompiled b/tests/run/valueclasses-pavlov.decompiled index fbf972b03c32..36da557e9f4c 100644 --- a/tests/run/valueclasses-pavlov.decompiled +++ b/tests/run/valueclasses-pavlov.decompiled @@ -8,7 +8,7 @@ final class Box1(val value: scala.Predef.String) extends scala.AnyVal() { false } } -object Box1 extends scala.AnyRef() +object Box1 /** Decompiled from out/runTestFromTasty/run/valueclasses-pavlov/Box2.class */ final class Box2(val value: scala.Predef.String) extends scala.AnyVal() with Foo { def box1(x: Box1): scala.Predef.String = "box1: ok" @@ -21,7 +21,7 @@ final class Box2(val value: scala.Predef.String) extends scala.AnyVal() with Foo false } } -object Box2 extends scala.AnyRef() +object Box2 /** Decompiled from out/runTestFromTasty/run/valueclasses-pavlov/C.class */ class C(x: scala.Predef.String) { def this() = {