summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/UnCurry.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-03-24 16:23:48 +0000
committerPaul Phillips <paulp@improving.org>2010-03-24 16:23:48 +0000
commitc7c8981b43a6df71e088b444dacf53d609a21ffc (patch)
tree68874111359ccd5335011daa949791bf3706062b /src/compiler/scala/tools/nsc/transform/UnCurry.scala
parentcb9f3c3d0ff62c45e316aac6b121db16e8fd859e (diff)
downloadscala-c7c8981b43a6df71e088b444dacf53d609a21ffc.tar.gz
scala-c7c8981b43a6df71e088b444dacf53d609a21ffc.tar.bz2
scala-c7c8981b43a6df71e088b444dacf53d609a21ffc.zip
Fixed an issue with no-parameter-list methods n...
Fixed an issue with no-parameter-list methods not being elided. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/UnCurry.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index c59450432f..950bace533 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -475,6 +475,16 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
}
}
+ /** For removing calls to specially designated methods.
+ */
+ def elideIntoUnit(tree: Tree): Tree = Literal(()) setPos tree.pos setType UnitClass.tpe
+ def isElidable(tree: Tree) = {
+ val sym = tree.symbol
+ // XXX settings.noassertions.value temporarily retained to avoid
+ // breakage until a reasonable interface is settled upon.
+ sym != null && sym.elisionLevel.exists(x => x < settings.elidebelow.value || settings.noassertions.value)
+ }
+
// ------ The tree transformers --------------------------------------------------------
def mainTransform(tree: Tree): Tree = {
@@ -579,21 +589,15 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
treeCopy.UnApply(tree, fn1, args1)
case Apply(fn, args) =>
- // XXX settings.noassertions.value temporarily retained to avoid
- // breakage until a reasonable interface is settled upon.
- def elideFunctionCall(sym: Symbol) =
- sym != null && sym.elisionLevel.exists(x => x < settings.elidebelow.value || settings.noassertions.value)
-
- if (elideFunctionCall(fn.symbol)) {
- Literal(()).setPos(tree.pos).setType(UnitClass.tpe)
- } else if (fn.symbol == Object_synchronized && shouldBeLiftedAnyway(args.head)) {
+ if (isElidable(fn))
+ elideIntoUnit(tree)
+ else if (fn.symbol == Object_synchronized && shouldBeLiftedAnyway(args.head))
transform(treeCopy.Apply(tree, fn, List(liftTree(args.head))))
- } else {
+ else
withNeedLift(true) {
val formals = fn.tpe.paramTypes
treeCopy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, fn.symbol, args, formals)))
}
- }
case Assign(Select(_, _), _) =>
withNeedLift(true) { super.transform(tree) }
@@ -632,16 +636,21 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
} setType uncurryTreeType(tree.tpe)
def postTransform(tree: Tree): Tree = atPhase(phase.next) {
- def applyUnary(): Tree =
- if (tree.symbol.isMethod &&
- (!tree.tpe.isInstanceOf[PolyType] || tree.tpe.typeParams.isEmpty)) {
- if (!tree.tpe.isInstanceOf[MethodType]) tree.tpe = MethodType(List(), tree.tpe);
- atPos(tree.pos)(Apply(tree, List()) setType tree.tpe.resultType)
- } else if (tree.isType) {
- TypeTree(tree.tpe) setPos tree.pos
- } else {
- tree
+ def applyUnary(): Tree = {
+ def needsParens = tree.symbol.isMethod && (!tree.tpe.isInstanceOf[PolyType] || tree.tpe.typeParams.isEmpty)
+ def repair = {
+ if (!tree.tpe.isInstanceOf[MethodType])
+ tree.tpe = MethodType(Nil, tree.tpe)
+
+ atPos(tree.pos)(Apply(tree, Nil) setType tree.tpe.resultType)
}
+
+ if (isElidable(tree)) elideIntoUnit(tree) // was not seen in mainTransform
+ else if (needsParens) repair
+ else if (tree.isType) TypeTree(tree.tpe) setPos tree.pos
+ else tree
+ }
+
tree match {
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
val rhs1 = nonLocalReturnKeys.get(tree.symbol) match {