summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2012-01-17 15:23:02 +0100
committerIulian Dragos <jaguarul@gmail.com>2012-01-17 15:25:28 +0100
commit1591c14e504246d2cb49b1f7f3e00f6d986f6a06 (patch)
tree30042b7fb7afcd0cd148d893f051571e39b4a90e
parentcebc49b9f37ec8c8a3befcee6142f9c0590c41e2 (diff)
downloadscala-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
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala5
-rw-r--r--test/files/specialized/spec-hlists.check2
-rw-r--r--test/files/specialized/spec-hlists.scala29
3 files changed, 35 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index 5d13f80897..cf25ebe591 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -1275,7 +1275,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
.format(tree, symbol.tpe, tree.tpe, env, specializedName(symbol, env)))
if (!env.isEmpty) { // a method?
val specCandidates = qual.tpe.member(specializedName(symbol, env))
- val specMember = specCandidates suchThat (s => doesConform(symbol, tree.tpe, s.tpe, env))
+ val specMember = specCandidates suchThat { s =>
+ doesConform(symbol, tree.tpe, qual.tpe.memberType(s), env)
+ }
+
log("[specSym] found: " + specCandidates.tpe + ", instantiated as: " + tree.tpe)
log("[specSym] found specMember: " + specMember)
if (specMember ne NoSymbol)
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)
+}