diff options
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/t0764.scala | 27 | ||||
-rw-r--r-- | test/files/pos/t0764b.scala | 61 | ||||
-rw-r--r-- | test/files/pos/t8177.scala | 12 | ||||
-rw-r--r-- | test/files/pos/t8177a.scala | 9 | ||||
-rw-r--r-- | test/files/pos/t8177b.scala | 13 | ||||
-rw-r--r-- | test/files/pos/t8177d.scala | 12 | ||||
-rw-r--r-- | test/files/pos/t8177e.scala | 3 | ||||
-rw-r--r-- | test/files/pos/t8177g.scala | 11 |
8 files changed, 148 insertions, 0 deletions
diff --git a/test/files/pos/t0764.scala b/test/files/pos/t0764.scala new file mode 100644 index 0000000000..f1084f5ff8 --- /dev/null +++ b/test/files/pos/t0764.scala @@ -0,0 +1,27 @@ +class Top[A] { + type AType = A +} + +trait Node { outer => + type T <: Node + def prepend = new Node { type T = outer.type } +} + +class Main[NextType <: Node](value: Node { type T = NextType }) + extends Top[Node { type T = NextType }] { + + new Main[AType]( (value: AType).prepend ) +} + +/* this used to be a neg test, even though it should've compiled +SI-8177 fixed this. + +Behold the equivalent program which type checks without the fix for SI-8177. +(Expand type alias, convert type member to type param; +note the covariance to encode subtyping on type members.) + +class Node[+T <: Node[_]] { def prepend = new Node[this.type] } +class Main[NextType <: Node[_]](value: Node[NextType]) { + new Main(value.prepend) +} +*/
\ No newline at end of file diff --git a/test/files/pos/t0764b.scala b/test/files/pos/t0764b.scala new file mode 100644 index 0000000000..6ae3c105c9 --- /dev/null +++ b/test/files/pos/t0764b.scala @@ -0,0 +1,61 @@ +// In all cases when calling "prepend" the receiver 'v' +// has static type NodeAlias[A] or (equivalently) Node { type T = A }. +// Since prepend explicitly returns the singleton type of the receiver, +// the return type of prepend in all cases is "v.type", and so the call +// to "new Main" can be parameterized with any of the following, in order +// of decreasing specificity with a tie for second place: +// +// new Main[v.type](v.prepend) +// new Main[NodeAlias[A]](v.prepend) +// new Main[Node { type T = A }](v.prepend) +// new Main(v.prepend) + +// the `fail` comments below denote what didn't compile before SI-8177 fixed all of them + +package p1 { + object t0764 { + type NodeAlias[A] = Node { type T = A } + trait Node { outer => + type T <: Node + def prepend: Node { type T = outer.type } = ??? + } + + class Main1[A <: Node](v: NodeAlias[A]) { + private[this] def f1 = new Main1(v.prepend) // fail + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main1[v.type](v.prepend) // ok + } + + class Main2[A <: Node](v: Node { type T = A }) { + private[this] def f1 = new Main2(v.prepend) // fail + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main2[v.type](v.prepend) // ok + } + } +} + +package p2 { + object t0764 { + type NodeAlias[A] = Node { type T = A } + trait Node { outer => + type T <: Node + def prepend: NodeAlias[outer.type] = ??? + } + + class Main1[A <: Node](v: NodeAlias[A]) { + private[this] def f1 = new Main1(v.prepend) // ok! <<========== WOT + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main1[v.type](v.prepend) // ok + } + + class Main2[A <: Node](v: Node { type T = A }) { + private[this] def f1 = new Main2(v.prepend) // fail + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main2[v.type](v.prepend) // ok + } + } +} diff --git a/test/files/pos/t8177.scala b/test/files/pos/t8177.scala new file mode 100644 index 0000000000..fe265f8d0a --- /dev/null +++ b/test/files/pos/t8177.scala @@ -0,0 +1,12 @@ +// exercise coevolveSym: SingleType with an underlying RefinedType +trait Thing { type A } +object IntThing extends Thing { type A = Int } + +// The following erroneously failed with error: method f overrides nothing. +// because asSeenFrom produced a typeref of the shape T'#A where A referred to a symbol defined in a T of times past +// More precisely, the TypeRef case of TypeMap's mapOver correctly modified prefix +// from having an underlying type of { type A = Ain } to { type A = Int }, with a new symbol for A (now with info Int), +// but the symbol in the outer type ref wasn't co-evolved (so it still referred to the { type A = AIn } underlying the old prefix) +// coEvolveSym used to only look at prefixes that were directly RefinedTypes, but they could also be SingleTypes with an underlying RefinedType +class View[AIn](val in: Thing { type A = AIn }) { def f(p: in.A): in.A = p } +class SubView extends View[Int](IntThing) { override def f(p: in.A): in.A = p } diff --git a/test/files/pos/t8177a.scala b/test/files/pos/t8177a.scala new file mode 100644 index 0000000000..7e2cfb386c --- /dev/null +++ b/test/files/pos/t8177a.scala @@ -0,0 +1,9 @@ +// exercise coevolveSym +trait Thing { type A; var p: A = _ } +class AA[T](final val x: Thing { type A = T }) { + def foo: x.A = ??? +} + +class B extends AA[Int](null) { + override def foo: B.this.x.A = super.foo +} diff --git a/test/files/pos/t8177b.scala b/test/files/pos/t8177b.scala new file mode 100644 index 0000000000..b7ed9342a3 --- /dev/null +++ b/test/files/pos/t8177b.scala @@ -0,0 +1,13 @@ +// exercise coevolveSym: SingleType with an underlying RefinedType, via a type alias +trait Thing { type A } +object IntThing extends Thing { type A = Int } +object ThingHolder { type Alias[AIn] = Thing { type A = AIn } } + +// The following erroneously failed with error: method f overrides nothing. +// because asSeenFrom produced a typeref of the shape T'#A where A referred to a symbol defined in a T of times past +// More precisely, the TypeRef case of TypeMap's mapOver correctly modified prefix +// from having an underlying type of { type A = Ain } to { type A = Int }, with a new symbol for A (now with info Int), +// but the symbol in the outer type ref wasn't co-evolved (so it still referred to the { type A = AIn } underlying the old prefix) +// coEvolveSym used to only look at prefixes that were directly RefinedTypes, but they could also be SingleTypes with an underlying RefinedType +class View[AIn](val in: ThingHolder.Alias[AIn]) { def f(p: in.A): in.A = p } +class SubView extends View[Int](IntThing) { override def f(p: in.A): in.A = p }
\ No newline at end of file diff --git a/test/files/pos/t8177d.scala b/test/files/pos/t8177d.scala new file mode 100644 index 0000000000..d15a05a359 --- /dev/null +++ b/test/files/pos/t8177d.scala @@ -0,0 +1,12 @@ +// exercise coevolveSym +trait HasElem { type A } +trait View[AIn] { + val tc: HasElem { type A = AIn } + def f2(p: tc.A): tc.A = p +} + +object Test { + val view: View[Int] = null + + view f2 5 // fails +} diff --git a/test/files/pos/t8177e.scala b/test/files/pos/t8177e.scala new file mode 100644 index 0000000000..cb1136ff11 --- /dev/null +++ b/test/files/pos/t8177e.scala @@ -0,0 +1,3 @@ +// exercise coevolveSym +trait T[A] { val foo: { type B = A } = ???; def bar(b: foo.B) = () } +object O extends T[Int] { bar(0) } diff --git a/test/files/pos/t8177g.scala b/test/files/pos/t8177g.scala new file mode 100644 index 0000000000..bb66d32021 --- /dev/null +++ b/test/files/pos/t8177g.scala @@ -0,0 +1,11 @@ +// exercise coevolveSym: ThisType +trait HasA { type A } +class AA[T] { + type HasAT[T] = HasA{ type A = T } + val x: HasAT[T] = ??? + def foo: x.A = ??? +} + +class B extends AA[Int] { + override def foo: B.this.x.A = super.foo +}
\ No newline at end of file |