diff options
author | Paul Phillips <paulp@improving.org> | 2011-10-11 22:17:32 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-10-11 22:17:32 +0000 |
commit | d3f0fa824b2fb12d71fe47187991abd31b47546a (patch) | |
tree | 2c116dfa30d234e95438d79b6da3763dc22e91b4 | |
parent | 168f8065ea1ca60eae11964078b189cfb04b5578 (diff) | |
download | scala-d3f0fa824b2fb12d71fe47187991abd31b47546a.tar.gz scala-d3f0fa824b2fb12d71fe47187991abd31b47546a.tar.bz2 scala-d3f0fa824b2fb12d71fe47187991abd31b47546a.zip |
Propagate self-type to specialized subclasses.
Closes SI-5071, review by prokopec.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala | 7 | ||||
-rw-r--r-- | test/files/pos/t5071.scala | 18 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 0f07ac0641..756c05a0c7 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -503,7 +503,12 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { val extraSpecializedMixins = specializedParents(clazz.info.parents.map(applyContext)) if (extraSpecializedMixins.nonEmpty) debuglog("specializeClass on " + clazz + " founds extra specialized mixins: " + extraSpecializedMixins.mkString(", ")) - + // If the class being specialized has a self-type, we have to propagate + // that information to the specialized subclasses or it vanishes. + if (clazz.thisSym ne clazz) { + cls.typeOfThis = applyContext(clazz.typeOfThis) + log("Rewriting self-type in specialized class: " + clazz.typeOfThis + " => " + cls.typeOfThis) + } val infoType = ClassInfoType(parents ::: extraSpecializedMixins, decls1, cls) if (newClassTParams.isEmpty) infoType else PolyType(newClassTParams, infoType) } diff --git a/test/files/pos/t5071.scala b/test/files/pos/t5071.scala new file mode 100644 index 0000000000..44ad6276f2 --- /dev/null +++ b/test/files/pos/t5071.scala @@ -0,0 +1,18 @@ +// abstract +trait Foo[@specialized A, Repr] { + self: Repr => +} +trait Bar[A] extends Foo[A, Object] { } +class Baz extends Foo[Int, Baz] { } + +// concrete +trait Bippy { + def f(x: Int) = 5 +} +trait FooC[@specialized A] { + self: Bippy => + + f(10) +} + +class BazC extends FooC[Int] with Bippy { } |