diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2012-01-17 15:23:02 +0100 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2012-01-17 15:25:28 +0100 |
commit | 1591c14e504246d2cb49b1f7f3e00f6d986f6a06 (patch) | |
tree | 30042b7fb7afcd0cd148d893f051571e39b4a90e /test | |
parent | cebc49b9f37ec8c8a3befcee6142f9c0590c41e2 (diff) | |
download | scala-1591c14e504246d2cb49b1f7f3e00f6d986f6a06.tar.gz scala-1591c14e504246d2cb49b1f7f3e00f6d986f6a06.tar.bz2 scala-1591c14e504246d2cb49b1f7f3e00f6d986f6a06.zip |
Make specialization pick up opportunities when the
specialized method has additional (non-specialized) type parameters.
This fix comes from Stefan's desire to specialize HLists (see
corresponding test). review by @prokopec
Diffstat (limited to 'test')
-rw-r--r-- | test/files/specialized/spec-hlists.check | 2 | ||||
-rw-r--r-- | test/files/specialized/spec-hlists.scala | 29 |
2 files changed, 31 insertions, 0 deletions
diff --git a/test/files/specialized/spec-hlists.check b/test/files/specialized/spec-hlists.check new file mode 100644 index 0000000000..0ab3339bbc --- /dev/null +++ b/test/files/specialized/spec-hlists.check @@ -0,0 +1,2 @@ +class HCons$mcI$sp +class HCons$mcI$sp diff --git a/test/files/specialized/spec-hlists.scala b/test/files/specialized/spec-hlists.scala new file mode 100644 index 0000000000..8c4ac8f610 --- /dev/null +++ b/test/files/specialized/spec-hlists.scala @@ -0,0 +1,29 @@ +/** Test contributed by Stefan Zeiger showing that HLists can be + * specialized. + */ + +sealed trait HList { + type Self <: HList + + type |: [E] = HCons[E, Self] + + final def |: [@specialized E](elem: E): |: [E] = new HCons[E, Self](elem, this.asInstanceOf[Self]) + + def m[@specialized E, T <: AnyRef](x: E): T = null.asInstanceOf[T] +} + +final class HCons[@specialized H, T <: HList](val head: H, val tail: T) extends HList { + type Self = HCons[H, T] +} + +final object HNil extends HList { + type Self = HNil.type +} + +object Test extends App { + val l1 = new HCons(42, "foo" |: HNil) + println(l1.getClass) + + val l2 = 42 |: "abc" |: HNil + println(l2.getClass) +} |