summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-01-21 10:45:36 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-01-21 11:12:57 +0100
commitf6168b8a4d661985b0fb4d6d3cbba256bfc69607 (patch)
tree386c6695d03fb0b3787ead0a4aececc47a24fa58 /src/compiler/scala/tools/nsc/transform/LambdaLift.scala
parent6f72ed85c3882d2a8c824a41e6e42d7f33b8d1d6 (diff)
downloadscala-f6168b8a4d661985b0fb4d6d3cbba256bfc69607.tar.gz
scala-f6168b8a4d661985b0fb4d6d3cbba256bfc69607.tar.bz2
scala-f6168b8a4d661985b0fb4d6d3cbba256bfc69607.zip
SI-6231 Report unsupported free var capture by a trait.
If a class nested in a trait captures a free variable from the enclosing scope of the trait, the transformation to add that variable to the `init` method of the trait implementation class happens *after* the abstract trait interface has been extracted. This would lead to a crash when trying to find the corresponding interface method. This commit detects this situation and reports an implementation restriction. The enclosed test case shows a workaround. To lift this restriction, LambdaLifter should add the getters and make sure they end up in the trait interface. Looks like Martin tried this once: // LambdaLift.scala // // Disabled attempt to to add getters to freeParams // this does not work yet. Problem is that local symbols need local names // and references to local symbols need to be transformed into // method calls to setters. // def paramGetter(param: Symbol): Tree = { // val getter = param.newGetter setFlag TRANS_FLAG resetFlag PARAMACCESSOR // mark because we have to add them to interface // sym.info.decls.enter(getter) // val rhs = Select(gen.mkAttributedThis(sym), param) setType param.tpe // DefDef(getter, rhs) setPos tree.pos setType NoType // } // val newDefs = if (sym.isTrait) freeParams ::: (ps map paramGetter) else freeParams
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/LambdaLift.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/LambdaLift.scala3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
index 4a23e65ad2..cd2bffcfde 100644
--- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
+++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
@@ -352,6 +352,7 @@ abstract class LambdaLift extends InfoTransform {
copyDefDef(tree)(vparamss = List(vparams ++ freeParams))
case ClassDef(_, _, _, _) =>
+ // SI-6231
// Disabled attempt to to add getters to freeParams
// this does not work yet. Problem is that local symbols need local names
// and references to local symbols need to be transformed into
@@ -369,7 +370,7 @@ abstract class LambdaLift extends InfoTransform {
tree
}
-/* Something like this will be necessary to eliminate the implementation
+/* SI-6231: Something like this will be necessary to eliminate the implementation
* restiction from paramGetter above:
* We need to pass getters to the interface of an implementation class.
private def fixTraitGetters(lifted: List[Tree]): List[Tree] =