summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-09-14 13:05:15 +0000
committerPaul Phillips <paulp@improving.org>2011-09-14 13:05:15 +0000
commit7cddbc6564521eb0affbd6ef0d8b5608e61e668f (patch)
tree5a39c5d4e9c19310049c6692c3f045e30b6fdcdf /src/compiler
parentb2f3fb271342d7862cc045f5ee5cff6815ac9722 (diff)
downloadscala-7cddbc6564521eb0affbd6ef0d8b5608e61e668f.tar.gz
scala-7cddbc6564521eb0affbd6ef0d8b5608e61e668f.tar.bz2
scala-7cddbc6564521eb0affbd6ef0d8b5608e61e668f.zip
Minor cleanup in Uncurry w/ NullaryMethodTypes.
No review.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/reflect/internal/TreeGen.scala8
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala21
2 files changed, 15 insertions, 14 deletions
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 {