summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert.plociniczak@gmail.com>2012-09-27 11:33:32 +0200
committerHubert Plociniczak <hubert.plociniczak@gmail.com>2012-10-09 21:49:41 +0200
commita15969a6963a896fa3a4aa43effaf625833e363d (patch)
tree28a3ff68beef43903cfb5df9938e75702369d5ed /src/compiler
parent63c90af33290c2df38e70982c8c0151df1b106a9 (diff)
downloadscala-a15969a6963a896fa3a4aa43effaf625833e363d.tar.gz
scala-a15969a6963a896fa3a4aa43effaf625833e363d.tar.bz2
scala-a15969a6963a896fa3a4aa43effaf625833e363d.zip
Incorporated changes suggested in code review
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/reflect/reify/phases/Reshape.scala6
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala19
3 files changed, 19 insertions, 11 deletions
diff --git a/src/compiler/scala/reflect/reify/phases/Reshape.scala b/src/compiler/scala/reflect/reify/phases/Reshape.scala
index ef099f9f1b..9a1732a872 100644
--- a/src/compiler/scala/reflect/reify/phases/Reshape.scala
+++ b/src/compiler/scala/reflect/reify/phases/Reshape.scala
@@ -297,7 +297,7 @@ trait Reshape {
val vdef1 = ValDef(mods2, name1, tpt, rhs)
if (reifyDebug) println("resetting visibility of field: %s => %s".format(vdef, vdef1))
Some(vdef1) // no copyAttrs here, because new ValDef and old symbols are now out of sync
- case ddef @ DefDef(mods, name, tparams, vparamss, tpt, rhs) if !ddef.mods.isLazy =>
+ case ddef: DefDef if !ddef.mods.isLazy =>
// lazy val accessors are removed in reshapeLazyVals
// as they are needed to recreate lazy vals
if (accessors.values.exists(_.contains(ddef))) {
@@ -319,7 +319,7 @@ trait Reshape {
// lazy valdef and defdef are in the same block.
// only that valdef needs to have its rhs rebuilt from defdef
stats flatMap (stat => stat match {
- case vdef @ ValDef(mods0, name0, tpt0, rhs0) if vdef.symbol.isLazy =>
+ case vdef: ValDef if vdef.symbol.isLazy =>
if (reifyDebug) println(s"reconstructing original lazy value for $vdef")
val ddefSym = vdef.symbol.lazyAccessor
val vdef1 = lazyvaldefs.get(ddefSym) match {
@@ -331,7 +331,7 @@ trait Reshape {
}
if (reifyDebug) println(s"reconstructed lazy val is $vdef1")
vdef1::Nil
- case ddef @ DefDef(mods0, name0, _, _, tpt0, rhs0) if ddef.symbol.isLazy =>
+ case ddef: DefDef if ddef.symbol.isLazy =>
def hasUnitType(sym: Symbol) = (sym.tpe.typeSymbol == UnitClass) && sym.tpe.annotations.isEmpty
if (hasUnitType(ddef.symbol)) {
// since lazy values of type Unit don't have val's
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index 32c2d63b2a..328e4ce71f 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -231,9 +231,8 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
extends ChangeOwnerTraverser(oldowner, newowner) {
override def traverse(tree: Tree) {
tree match {
- case Return(expr) =>
- if (tree.symbol == oldowner) tree.symbol = newowner
- case _ =>
+ case _: Return => change(tree.symbol)
+ case _ =>
}
super.traverse(tree)
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
index 8e803a9a9e..c95951e608 100644
--- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
@@ -454,21 +454,30 @@ trait MethodSynthesis {
* { z = <rhs>; z } where z can be an identifier or a field.
*/
case class LazyValGetter(tree: ValDef) extends BaseGetter(tree) {
+ class ChangeOwnerAndModuleClassTraverser(oldowner: Symbol, newowner: Symbol)
+ extends ChangeOwnerTraverser(oldowner, newowner) {
+
+ override def traverse(tree: Tree) {
+ tree match {
+ case _: DefTree => change(tree.symbol.moduleClass)
+ case _ =>
+ }
+ super.traverse(tree)
+ }
+ }
+
// todo: in future this should be enabled but now other phases still depend on the flag for various reasons
//override def flagsMask = (super.flagsMask & ~LAZY)
override def derivedSym = basisSym.lazyAccessor
override def derivedTree: DefDef = {
val ValDef(_, _, tpt0, rhs0) = tree
- val rhs1 = transformed.get(rhs0) match {
- case Some(rhs) => rhs
- case None => rhs0
- }
+ val rhs1 = transformed.getOrElse(rhs0, rhs0)
val body = (
if (tree.symbol.owner.isTrait || hasUnitType(basisSym)) rhs1
else gen.mkAssignAndReturn(basisSym, rhs1)
)
derivedSym.setPos(tree.pos) // cannot set it at createAndEnterSymbol because basisSym can possible stil have NoPosition
- val ddefRes = atPos(tree.pos)(DefDef(derivedSym, body.changeOwner(followModuleClass = true, basisSym -> derivedSym)))
+ val ddefRes = atPos(tree.pos)(DefDef(derivedSym, new ChangeOwnerAndModuleClassTraverser(basisSym, derivedSym)(body)))
// ValDef will have its position focused whereas DefDef will have original correct rangepos
// ideally positions would be correct at the creation time but lazy vals are really a special case
// here so for the sake of keeping api clean we fix positions manually in LazyValGetter