diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-13 12:28:06 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-13 18:53:06 -0800 |
commit | 33fc68171105bb8d884219381c220076c5651316 (patch) | |
tree | d09484d6b415d5877e6dde5a3ead189ec6952414 /test/files/neg | |
parent | c83e01d47d941265fa5415c0f29a884c904fdfa0 (diff) | |
download | scala-33fc68171105bb8d884219381c220076c5651316.tar.gz scala-33fc68171105bb8d884219381c220076c5651316.tar.bz2 scala-33fc68171105bb8d884219381c220076c5651316.zip |
SI-8177 specializeSym must use memberInfo on high side
When determining whether member `symLo` of `tpLo`
has a stronger type than member `symHi` of `tpHi`,
should we use memberType or memberInfo?
Well, memberType transforms (using `asSeenFrom`) `sym.tpe`,
whereas memberInfo performs the same transform on `sym.info`.
For term symbols, this ends up being the same thing (`sym.tpe == sym.info`).
For type symbols, however, the `.info` of an abstract type member
is defined by its bounds, whereas its `.tpe` is a `TypeRef` to that type symbol,
so that `sym.tpe <:< sym.info`, but not the other way around.
Thus, for the strongest (correct) result,
we should use `memberType` on the low side.
On the high side, we should use the result appropriate
for the right side of the `<:<` above (`memberInfo`).
I also optimized the method a little bit by avoiding calling memberType
if the symbol on the high side isn't eligble (e.g., it's a class).
PS: I had to add a workaround to reifyType, because
we now dealias a little less eagerly, which means
a type selection on refinement class symbols makes it to reify
this broke the t8104 tests.
I also had to update the run/t6992 test, which should now test the right thing.
Tests should be commented and/or use sensible names.
What is it testing? What is the expected outcome? We should not be left guessing.
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/t0764.check | 7 | ||||
-rw-r--r-- | test/files/neg/t0764.scala | 45 | ||||
-rw-r--r-- | test/files/neg/t0764b.check | 47 | ||||
-rw-r--r-- | test/files/neg/t0764b.scala | 63 | ||||
-rw-r--r-- | test/files/neg/t8177a.check | 6 | ||||
-rw-r--r-- | test/files/neg/t8177a.scala | 6 |
6 files changed, 174 insertions, 0 deletions
diff --git a/test/files/neg/t0764.check b/test/files/neg/t0764.check new file mode 100644 index 0000000000..0c7cff1e1e --- /dev/null +++ b/test/files/neg/t0764.check @@ -0,0 +1,7 @@ +t0764.scala:13: error: type mismatch; + found : Node{type T = _1.type} where val _1: Node{type T = NextType} + required: Node{type T = Main.this.AType} + (which expands to) Node{type T = Node{type T = NextType}} + new Main[AType]( (value: AType).prepend ) + ^ +one error found diff --git a/test/files/neg/t0764.scala b/test/files/neg/t0764.scala new file mode 100644 index 0000000000..9f77a59414 --- /dev/null +++ b/test/files/neg/t0764.scala @@ -0,0 +1,45 @@ +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 ) +} + +/* we've been back-and-forth on this one -- see PRs on SI-8177 for the reasoning +I think it should compile and that the following error is due to broken =:= on existentials + found : Node{type T = _1.type} where val _1: Node{type T = NextType} + required: Node{type T = Main.this.AType} + (which expands to) Node{type T = Node{type T = NextType}} + +I claim (omitting the forSome for brevity, even though the premature skolemization is probably the issue) +_1.type =:= Main.this.AType +because +(1) _1.type <:< Main.this.AType and (2) Main.this.AType <:< _1.type +(1), because: +_1.type <:< Node{type T = NextType} (because skolemization and _1's upper bound) +(2), because: +Node{type T = NextType} <:< _1.type forSome val _1: Node{type T = NextType} +because: +Node{type T = NextType} <:< T forSome {type T <: Node{type T = NextType} with Singleton} +because +Node{type T = NextType} <:< Node{type T = NextType} with Singleton + +hmmm.. might the with Singleton be throwing a wrench in our existential house? + +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/neg/t0764b.check b/test/files/neg/t0764b.check new file mode 100644 index 0000000000..4040954e7c --- /dev/null +++ b/test/files/neg/t0764b.check @@ -0,0 +1,47 @@ +t0764b.scala:27: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.NodeAlias[p1.t0764.NodeAlias[A]] + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:28: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.NodeAlias[p1.t0764.Node{type T = A}] + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:34: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.Node{type T = p1.t0764.NodeAlias[A]} + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:35: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:51: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.NodeAlias[p2.t0764.NodeAlias[A]] + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:52: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.NodeAlias[p2.t0764.Node{type T = A}] + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:58: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.Node{type T = p2.t0764.NodeAlias[A]} + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:59: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + ^ +8 errors found diff --git a/test/files/neg/t0764b.scala b/test/files/neg/t0764b.scala new file mode 100644 index 0000000000..14c623c67a --- /dev/null +++ b/test/files/neg/t0764b.scala @@ -0,0 +1,63 @@ +// see neg/t0764 why this should probably be a pos/ test -- alas something's wrong with existential subtyping (?) + +// 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/neg/t8177a.check b/test/files/neg/t8177a.check new file mode 100644 index 0000000000..0d01206e0c --- /dev/null +++ b/test/files/neg/t8177a.check @@ -0,0 +1,6 @@ +t8177a.scala:5: error: type mismatch; + found : A{type Result = Int} + required: A{type Result = String} + : A { type Result = String} = x + ^ +one error found diff --git a/test/files/neg/t8177a.scala b/test/files/neg/t8177a.scala new file mode 100644 index 0000000000..d1e47f8c1e --- /dev/null +++ b/test/files/neg/t8177a.scala @@ -0,0 +1,6 @@ +trait A { type Result } + +class PolyTests { + def wrong(x: A { type Result = Int }) + : A { type Result = String} = x +}
\ No newline at end of file |