Skip to content

Commit 231b874

Browse files
committed
Fix #4557: Handle untpd.New with dealiased type
1 parent d79b57e commit 231b874

13 files changed

+173
-9
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
311311
val (tycon, targs) = tpt match {
312312
case AppliedTypeTree(tycon, targs) =>
313313
(tycon, targs)
314-
case TypedSplice(AppliedTypeTree(tycon, targs)) =>
315-
(TypedSplice(tycon), targs map (TypedSplice(_)))
316314
case TypedSplice(tpt1: tpd.Tree) =>
317-
val tycon = tpt1.tpe.typeConstructor
318-
val argTypes = tpt1.tpe.argTypesLo
315+
val tp = tpt1.tpe.dealias
316+
val tycon = tp.typeConstructor
317+
val argTypes = tp.argTypesLo
319318
def wrap(tpe: Type) = TypeTree(tpe) withPos tpt.pos
320319
(wrap(tycon), argTypes map wrap)
321320
case _ =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ class Typer extends Namer
516516
case TypeApplications.EtaExpansion(tycon) => tpt1 = tpt1.withType(tycon)
517517
case _ =>
518518
}
519-
checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true)
519+
if (checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) eq defn.ObjectType)
520+
tpt1 = TypeTree(defn.ObjectType).withPos(tpt1.pos)
520521

521522
tpt1 match {
522523
case AppliedTypeTree(_, targs) =>

tests/neg/i4557.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class C0[A]
2+
class C1[A, B]
3+
4+
object O {
5+
type T0 = C0
6+
type T1 = C0[String, Int] // error
7+
type T2[A] = C0[A, Int] // error
8+
9+
type S0 = C1
10+
type S1 = C1[Int] // error
11+
12+
class D0 extends T0 // error
13+
class D1 extends T0[Int]
14+
class D2 extends T0[String, Int] // error
15+
16+
class E0 extends S0 // error
17+
class E1 extends S0[Int] // error
18+
class E2 extends S0[String, Int]
19+
}

tests/neg/i4557a.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A[X]
2+
3+
object T {
4+
type Foo[X, Y] = [Z] => A[X]
5+
class B extends Foo[Int, Int] // error
6+
}

tests/pos/i2104b.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ case class Pair[A, B](_1: A, _2: B) {
3131
throw new java.lang.IndexOutOfBoundsException(n.toString())
3232
}
3333
}
34-
object Pair extends scala.AnyRef()
34+
object Pair
3535
/** Decompiled from out/posTestFromTasty/pos/i2104b/Test.class */
3636
object Test {
3737
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {

tests/pos/i4557.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Parser[T, Elem]
2+
3+
object Test {
4+
type P[T] = Parser[T, Char]
5+
class CustomParser extends P[Unit]
6+
}

tests/pos/i4557a.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A[X]
2+
object O {
3+
type T[X, Y] = A[X]
4+
type S[X, Y] = T[X, Y]
5+
class B extends S[Int, Int]
6+
}

tests/pos/simpleCaseClass-3.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ case class A[T](x: T) {
2222
throw new java.lang.IndexOutOfBoundsException(n.toString())
2323
}
2424
}
25-
object A extends scala.AnyRef()
25+
object A

tests/run/i4557.check

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
c0
2+
c0
3+
c1
4+
0
5+
c1
6+
1
7+
c1
8+
2
9+
c1
10+
3
11+
c2
12+
0
13+
a
14+
c2
15+
1
16+
b
17+
c2
18+
2
19+
c
20+
c2
21+
3
22+
d
23+
c2
24+
4
25+
e
26+
c2
27+
5
28+
f

tests/run/i4557.scala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
trait F {
2+
def f: Unit
3+
}
4+
5+
abstract class C0 extends F {
6+
def f = println("c0")
7+
}
8+
9+
abstract class C1[A](val a: A) extends F {
10+
def f = {
11+
println("c1")
12+
println(a)
13+
}
14+
}
15+
16+
abstract class C2[A, B](val a: A, val b: B) extends F {
17+
def f = {
18+
println("c2")
19+
println(a)
20+
println(b)
21+
}
22+
}
23+
24+
object Test {
25+
type T0 = C0
26+
class DC0 extends C0
27+
class DT0 extends T0
28+
29+
type T1[T] = C1[T]
30+
class DC1 extends C1[Int](0)
31+
class DT1 extends T1[Int](1)
32+
33+
type T11 = C1[Int]
34+
class DT11 extends T11(2)
35+
36+
type T12 = C1
37+
class DT12 extends T12[Int](3)
38+
39+
type T2[T, S] = C2[T, S]
40+
class DC2 extends C2[Int, String](0, "a")
41+
class DT2 extends T2[Int, String](1, "b")
42+
43+
type T21[T] = C2[T, String]
44+
class DT21 extends T21[Int](2, "c")
45+
46+
type T22 = C2[Int, String]
47+
class DT22 extends T22(3, "d")
48+
49+
type T23[T, S] = T2[T, S]
50+
class DT23 extends T23(4, "e")
51+
52+
type T24 = C2
53+
class DT24 extends T24[Int, String](5, "f")
54+
55+
def main(args: Array[String]) = {
56+
List(
57+
new DC0,
58+
new DT0,
59+
new DC1,
60+
new DT1,
61+
new DT11,
62+
new DT12,
63+
new DC2,
64+
new DT2,
65+
new DT21,
66+
new DT22,
67+
new DT23,
68+
new DT24
69+
).foreach(_.f)
70+
}
71+
}

tests/run/i4557a.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
a
3+
2
4+
b

tests/run/i4557a.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
abstract class C0[X, Y, Z, W](x: X, y: Y, z: Z, w: W) {
2+
def f: Unit = {
3+
println(x)
4+
println(y)
5+
println(z)
6+
println(w)
7+
}
8+
}
9+
10+
object Test {
11+
type T0[X, Y, Z, A, B, C] = C0[X, Y, Z, A]
12+
type T1[A, B, C, D] = T0[A, B, C, D, Nothing, Any]
13+
type T2[E, F] = T1[E, F, E, F]
14+
type T3[X, Y, Z] = T2[X, Z]
15+
type T4[X, Y, Z, W] = T3[X, W, Y]
16+
type T5[A, B] = T4[A, B, (Int, Int), Unit]
17+
type T6 = T5[Int, String]
18+
19+
class D extends T6(1, "a", 2, "b")
20+
21+
def main(args: Array[String]) = {
22+
(new D).f
23+
}
24+
}

tests/run/valueclasses-pavlov.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ final class Box1(val value: scala.Predef.String) extends scala.AnyVal() {
88
false
99
}
1010
}
11-
object Box1 extends scala.AnyRef()
11+
object Box1
1212
/** Decompiled from out/runTestFromTasty/run/valueclasses-pavlov/Box2.class */
1313
final class Box2(val value: scala.Predef.String) extends scala.AnyVal() with Foo {
1414
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
2121
false
2222
}
2323
}
24-
object Box2 extends scala.AnyRef()
24+
object Box2
2525
/** Decompiled from out/runTestFromTasty/run/valueclasses-pavlov/C.class */
2626
class C(x: scala.Predef.String) {
2727
def this() = {

0 commit comments

Comments
 (0)