diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-04-16 21:56:30 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-04-16 21:56:30 +0200 |
commit | 2fbd539e353fd9d234f9a633d7606529d871d939 (patch) | |
tree | 5b04839c2c8942be64c88abad41d94a21b78afdb /test/files/run | |
parent | d2a174d27bce392329a9c5e4c7d2acee263cdb34 (diff) | |
download | scala-2fbd539e353fd9d234f9a633d7606529d871d939.tar.gz scala-2fbd539e353fd9d234f9a633d7606529d871d939.tar.bz2 scala-2fbd539e353fd9d234f9a633d7606529d871d939.zip |
Don't crash GenBCode for value classes with a self declaration
If a value class has a self declaration
class V(x: Long) extends AnyVal { self => /* ... */ }
`vClassSymbol.typeOfThis.typeSymbol` is `class Long` in the backend.
The InlineInfo for traits contains a field for the self type of the
trait. This is required for re-writing calls to final trait methods
to the static implementation method: the self type appears in the
impl method signature.
By mistake, the backend was recording the self type of all classes,
not only of traits. In the case of a value class with a self
declaration, this broke the assumption that the self type is always
a class type (not a primitive type).
The simple fix: only record the self type for traits.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/valueClassSelfType.scala | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/files/run/valueClassSelfType.scala b/test/files/run/valueClassSelfType.scala new file mode 100644 index 0000000000..47a3764b0a --- /dev/null +++ b/test/files/run/valueClassSelfType.scala @@ -0,0 +1,52 @@ +trait T + +class V1(val l: Long) extends AnyVal { self: T => + def foo: V1 = self + def bar: T = self +} + +class V2(val l: Long) extends AnyVal { self => + def foo: V2 = self +} + +class V3(val l: Long) extends AnyVal { self: Long => + def foo: V3 = self + def bar: Long = self +} + +// non-value classes + +class C1(val l: Long) { self: T => + def foo: C1 = self + def bar: T = self +} + +class C2(val l: Long) { self => + def foo: C2 = self +} + +class C3(val l: Long) { self: Long => + def foo: C3 = self + def bar: Long = self +} + +object Test extends App { + // Rejected: superclass V1 is not a subclass of the superclass Object of the mixin trait T + // new V1(1l) with T + + assert(new V2(1l).foo.l == 1l) + + // Rejected: V3 does not conform to its self-type V3 with Long + // new V3(1l) + + val c2 = new C1(2l) with T + assert(c2.foo.l + c2.bar.asInstanceOf[C1].l == 4l) + + assert(new C2(3l).foo.l == 3l) + + // Rejected: C3 does not conform to its self-type C3 with Long + // new C3(4l) + + // Rejected: class Long needs to be a trait to be mixed in + // new C3(4l) with Long +} |