From 7cddbc6564521eb0affbd6ef0d8b5608e61e668f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 14 Sep 2011 13:05:15 +0000 Subject: Minor cleanup in Uncurry w/ NullaryMethodTypes. No review. --- src/compiler/scala/reflect/internal/TreeGen.scala | 8 ++++---- .../scala/tools/nsc/transform/UnCurry.scala | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala index 61c4edf75e..e10a52f0cb 100644 --- a/src/compiler/scala/reflect/internal/TreeGen.scala +++ b/src/compiler/scala/reflect/internal/TreeGen.scala @@ -71,12 +71,12 @@ abstract class TreeGen { if (clazz.isEffectiveRoot) EmptyTree else mkAttributedThis(clazz) case SingleType(pre, sym) => - applyIfNoArgs(mkAttributedStableRef(pre, sym)) + mkApplyIfNeeded(mkAttributedStableRef(pre, sym)) case TypeRef(pre, sym, args) => if (sym.isRoot) { mkAttributedThis(sym) } else if (sym.isModuleClass) { - applyIfNoArgs(mkAttributedRef(pre, sym.sourceModule)) + mkApplyIfNeeded(mkAttributedRef(pre, sym.sourceModule)) } else if (sym.isModule || sym.isClass) { assert(phase.erasedTypes, tpe) mkAttributedThis(sym) @@ -106,8 +106,8 @@ abstract class TreeGen { /** If this is a reference to a method with an empty * parameter list, wrap it in an apply. */ - private def applyIfNoArgs(qual: Tree) = qual.tpe match { - case MethodType(Nil, restpe) => Apply(qual, Nil) setType restpe + def mkApplyIfNeeded(qual: Tree) = qual.tpe match { + case MethodType(Nil, restpe) => atPos(qual.pos)(Apply(qual, Nil) setType restpe) case _ => qual } diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 056a366c3d..3965359094 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -544,17 +544,18 @@ abstract class UnCurry extends InfoTransform def postTransform(tree: Tree): Tree = atPhase(phase.next) { def applyUnary(): Tree = { - def needsParens = tree.symbol.isMethod && !tree.tpe.isInstanceOf[PolyType] // TODO_NMT: verify that the inner tree of a type-apply also gets parens if the whole tree is a polymorphic nullary method application - def repair = { - if (!tree.tpe.isInstanceOf[MethodType]) // i.e., it's a NullaryMethodType - tree.tpe = MethodType(Nil, tree.tpe.resultType) // TODO_NMT: I think the original `tree.tpe` was wrong, since that would set the method's resulttype to PolyType(Nil, restp) instead of restp - - atPos(tree.pos)(Apply(tree, Nil) setType tree.tpe.resultType) + // TODO_NMT: verify that the inner tree of a type-apply also gets parens if the + // whole tree is a polymorphic nullary method application + def removeNullary() = tree.tpe match { + case MethodType(_, _) => tree + case tp => tree setType MethodType(Nil, tp.resultType) } - - if (needsParens) repair - else if (tree.isType) TypeTree(tree.tpe) setPos tree.pos - else tree + if (tree.symbol.isMethod && !tree.tpe.isInstanceOf[PolyType]) + gen.mkApplyIfNeeded(removeNullary()) + else if (tree.isType) + TypeTree(tree.tpe) setPos tree.pos + else + tree } tree match { -- cgit v1.2.3