summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-12-07 15:39:51 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2016-12-07 15:39:51 +0100
commit0f3f635d30551b1b96c64b955a85a3e535d1f2d2 (patch)
tree03b35095a9793774caa9f7c0910bdba76eb4a4e6
parentee1c02b374a4b8a053e9a8b14af5e205afa67e14 (diff)
downloadscala-0f3f635d30551b1b96c64b955a85a3e535d1f2d2.tar.gz
scala-0f3f635d30551b1b96c64b955a85a3e535d1f2d2.tar.bz2
scala-0f3f635d30551b1b96c64b955a85a3e535d1f2d2.zip
SI-10072 cast Function nodes to environment in specialization
This commit basically make sure the fix for SI-5284 works correctly when a Function node reaches specialization (`-Ydealmbdafy:method` and IndyLambda are default in 2.12.x). To understand it, best read the excellent description in b29c01b. The code that's removed in this commit was added in 13ea590. It prevented `castType` from being invoked on the `Function` node, which is exactly what is needed here. It's also what happens under `-Ydelambdafy:inline`, the `new anonfun()` tree is being casted from `(Int, Int) => Int` to `(Int, A) => Int`.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Duplicators.scala4
-rw-r--r--test/files/run/t10072.scala18
2 files changed, 18 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
index df014b5161..ea82739504 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
@@ -240,10 +240,6 @@ abstract class Duplicators extends Analyzer {
result.symbol.updateAttachment(DelambdafyTarget)
result
- case fun: Function =>
- debuglog("Clearing the type and retyping Function: " + fun)
- super.typed(fun.clearType, mode, pt)
-
case vdef @ ValDef(mods, name, tpt, rhs) =>
// log("vdef fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol + " and " + invalidSyms)
//if (mods.hasFlag(Flags.LAZY)) vdef.symbol.resetFlag(Flags.MUTABLE) // Martin to Iulian: lazy vars can now appear because they are no longer boxed; Please check that deleting this statement is OK.
diff --git a/test/files/run/t10072.scala b/test/files/run/t10072.scala
new file mode 100644
index 0000000000..0f1dca1838
--- /dev/null
+++ b/test/files/run/t10072.scala
@@ -0,0 +1,18 @@
+trait T[A] {
+ def a: A
+ def foldLeft[B](zero: B, op: (B, A) => B): B = op(zero, a)
+ def sum[B >: A](zero: B): B
+}
+
+class C[@specialized(Int) A](val a: A) extends T[A] {
+ override def sum[@specialized(Int) B >: A](zero: B): B = foldLeft(zero, (x: B, y: B) => x)
+}
+
+object Test extends App {
+ def factory[T](a: T): C[T] = new C[T](a)
+
+ assert(new C[Int](1).sum(2) == 2)
+ assert(new C[String]("ho").sum("hu") == "hu")
+ assert(factory[Int](1).sum(2) == 2)
+ assert(factory[String]("ho").sum("hu") == "hu")
+}