summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-06-02 13:24:00 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-06-03 14:16:54 +0200
commit09bf95675b06a0912ab1e3c8cdcab9a19eca48d4 (patch)
treedeebbe85cb6a92dbdff4102cdda6f075841354c8 /src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
parent85cd96da352c929ea0ce4ba236730579e09c5c4b (diff)
downloadscala-09bf95675b06a0912ab1e3c8cdcab9a19eca48d4.tar.gz
scala-09bf95675b06a0912ab1e3c8cdcab9a19eca48d4.tar.bz2
scala-09bf95675b06a0912ab1e3c8cdcab9a19eca48d4.zip
SI-5167 An impl class method should refer to its own parameter symbols.
Rather than those of the original method in the trait. If they are shared, parameter renaming in the implementaion class is visible in the original method. This led to a crash in the resident compiler when looking up the default argument getter.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/AddInterfaces.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index e5fc98f23c..8c5d25e6c4 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -257,11 +257,21 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
/** Transforms the member tree containing the implementation
* into a member of the impl class.
*/
- private def implMethodDef(tree: Tree): Tree = (
- implMethodMap get tree.symbol
- map (impl => new ChangeOwnerAndReturnTraverser(tree.symbol, impl)(tree setSymbol impl))
- getOrElse abort("implMethod missing for " + tree.symbol)
- )
+ private def implMethodDef(tree: Tree): Tree = {
+ val impl = implMethodMap.getOrElse(tree.symbol, abort("implMethod missing for " + tree.symbol))
+
+ val newTree = if (impl.isErroneous) tree else { // e.g. res/t687
+ // SI-5167: Ensure that the tree that we are grafting refers the parameter symbols from the
+ // new method symbol `impl`, rather than the symbols of the original method signature in
+ // the trait. `tree setSymbol impl` does *not* suffice!
+ val DefDef(_, _, _, vparamss, _, _) = tree
+ val oldSyms = vparamss.flatten.map(_.symbol)
+ val newSyms = impl.info.paramss.flatten
+ assert(oldSyms.length == newSyms.length, (oldSyms, impl, impl.info))
+ tree.substTreeSyms(oldSyms, newSyms)
+ }
+ new ChangeOwnerAndReturnTraverser(newTree.symbol, impl)(newTree setSymbol impl)
+ }
/** Add mixin constructor definition
* def $init$(): Unit = ()