Skip to content

Fix #4557: Handle untpd.New with HKTypeLambda #4798

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 1 commit into from
Jul 25, 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
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
19 changes: 19 additions & 0 deletions tests/neg/i4557.scala
Original file line number Diff line number Diff line change
@@ -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]
}
6 changes: 6 additions & 0 deletions tests/neg/i4557a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class A[X]

object T {
type Foo[X, Y] = [Z] => A[X]
class B extends Foo[Int, Int] // error
}
2 changes: 1 addition & 1 deletion tests/pos/i2104b.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i4557.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Parser[T, Elem]

object Test {
type P[T] = Parser[T, Char]
class CustomParser extends P[Unit]
}
6 changes: 6 additions & 0 deletions tests/pos/i4557a.scala
Original file line number Diff line number Diff line change
@@ -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]
}
2 changes: 1 addition & 1 deletion tests/pos/simpleCaseClass-3.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ case class A[T](x: T) {
throw new java.lang.IndexOutOfBoundsException(n.toString())
}
}
object A extends scala.AnyRef()
object A
28 changes: 28 additions & 0 deletions tests/run/i4557.check
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions tests/run/i4557.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions tests/run/i4557a.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1
a
2
b
24 changes: 24 additions & 0 deletions tests/run/i4557a.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 2 additions & 2 deletions tests/run/valueclasses-pavlov.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() = {
Expand Down