summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-11-11 20:53:13 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-11-12 13:55:12 -0800
commit5160387dbd34e8f7d800244d0d6234a6f4540e73 (patch)
tree1b339293ac30aa14b73f041c25e0dcc89017b6be
parent9050aaf60fcbbe9465e63fe39963fa14f7af2776 (diff)
downloadscala-5160387dbd34e8f7d800244d0d6234a6f4540e73.tar.gz
scala-5160387dbd34e8f7d800244d0d6234a6f4540e73.tar.bz2
scala-5160387dbd34e8f7d800244d0d6234a6f4540e73.zip
Clean up a bit more in Constructors.
Comment about my poor naming choice in Types. NullaryMethodType sounds like the method has one empty argument list, whereas it really has no argument lists at all.
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala24
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala2
2 files changed, 14 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 2f019c75c9..f5eca11c98 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -359,7 +359,7 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
}
log("merging: " + originalStats.mkString("\n") + "\nwith\n" + specializedStats.mkString("\n"))
- val res = for (s <- originalStats; stat = s.duplicate) yield {
+ for (s <- originalStats; stat = s.duplicate) yield {
log("merge: looking at " + stat)
val stat1 = stat match {
case Assign(sel @ Select(This(_), field), _) =>
@@ -389,9 +389,8 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
} else
stat1
}
- if (specBuf.nonEmpty)
- println("residual specialized constructor statements: " + specBuf)
- res
+// if (specBuf.nonEmpty)
+// println("residual specialized constructor statements: " + specBuf)
}
/* Add an 'if' around the statements coming after the super constructor. This
@@ -591,7 +590,7 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
case ValDef(mods, name, _, _) if mods hasFlag PRESUPER =>
// stat is the constructor-local definition of the field value
val fields = presupers filter (_.getterName == name)
- assert(fields.length == 1)
+ assert(fields.length == 1, s"expected exactly one field by name $name in $presupers of $clazz's early initializers")
val to = fields.head.symbol
if (memoizeValue(to)) constrStatBuf += mkAssign(to, Ident(stat.symbol))
@@ -607,9 +606,9 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
// it goes before the superclass constructor call, otherwise it goes after.
// A lazy val's effect is not moved to the constructor, as it is delayed.
// Returns `true` when a `ValDef` is needed.
- def moveEffectToCtor(mods: Modifiers, rhs: Tree, memoized: Boolean): Unit = {
+ def moveEffectToCtor(mods: Modifiers, rhs: Tree, assignSym: Symbol): Unit = {
val initializingRhs =
- if (!memoized || statSym.isLazy) EmptyTree // not memoized, or effect delayed (for lazy val)
+ if ((assignSym eq NoSymbol) || statSym.isLazy) EmptyTree // not memoized, or effect delayed (for lazy val)
else if (!mods.hasStaticFlag) intoConstructor(statSym, primaryConstr.symbol)(rhs)
else rhs
@@ -619,7 +618,7 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
else if (mods hasFlag PRESUPER | PARAMACCESSOR) constrPrefixBuf
else constrStatBuf
- initPhase += mkAssign(statSym, initializingRhs)
+ initPhase += mkAssign(assignSym, initializingRhs)
}
}
@@ -640,10 +639,11 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
// - the constructor, before the super call (early initialized or a parameter accessor),
// - the constructor, after the super call (regular val).
case ValDef(mods, _, _, rhs) =>
- val emitField = memoizeValue(statSym)
- moveEffectToCtor(mods, rhs, emitField)
-
- if (emitField) defBuf += deriveValDef(stat)(_ => EmptyTree)
+ if (rhs ne EmptyTree) {
+ val emitField = memoizeValue(statSym)
+ moveEffectToCtor(mods, rhs, if (emitField) statSym else NoSymbol)
+ if (emitField) defBuf += deriveValDef(stat)(_ => EmptyTree)
+ } else defBuf += stat
// all other statements go into the constructor
case _ => constrStatBuf += intoConstructor(impl.symbol, primaryConstr.symbol)(stat)
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 33592bbd86..b282026c36 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -2496,6 +2496,8 @@ trait Types
override def isJava = true
}
+ // TODO: rename so it's more appropriate for the type that is for a method without argument lists
+ // ("nullary" erroneously implies it has an argument list with zero arguments, it actually has zero argument lists)
case class NullaryMethodType(override val resultType: Type) extends Type with NullaryMethodTypeApi {
override def isTrivial = resultType.isTrivial && (resultType eq resultType.withoutAnnotations)
override def prefix: Type = resultType.prefix