diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-26 11:34:38 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-26 11:37:20 -0700 |
commit | 742cb71ec8c8205af032df609088affc12d3e1c5 (patch) | |
tree | 5de7ebbb7eec4a3678c94ed68026fb4003989f71 | |
parent | b716261a7b29bcf613cb4e3b47ca2fb5a97380bb (diff) | |
download | scala-742cb71ec8c8205af032df609088affc12d3e1c5.tar.gz scala-742cb71ec8c8205af032df609088affc12d3e1c5.tar.bz2 scala-742cb71ec8c8205af032df609088affc12d3e1c5.zip |
Don't write side-effecting nullary methods.
Style says never write methods like this:
def foo: Unit
If it is Unit, then it is side-effecting, and should be
def foo(): Unit
Since -Xlint warns about this, we must adhere to its dictate.
6 files changed, 25 insertions, 26 deletions
diff --git a/src/actors-migration/scala/actors/migration/StashingActor.scala b/src/actors-migration/scala/actors/migration/StashingActor.scala index 9c3917b65e..d0a1432e72 100644 --- a/src/actors-migration/scala/actors/migration/StashingActor.scala +++ b/src/actors-migration/scala/actors/migration/StashingActor.scala @@ -18,7 +18,7 @@ trait StashingActor extends InternalActor { type Receive = PartialFunction[Any, Unit] // checks if StashingActor is created within the actorOf block - creationCheck; + creationCheck() private[actors] val ref = new InternalActorRef(this) @@ -112,8 +112,7 @@ trait StashingActor extends InternalActor { /* * Checks that StashingActor can be created only by MigrationSystem.actorOf method. */ - private[this] def creationCheck = { - + private[this] def creationCheck(): Unit = { // creation check (see ActorRef) val context = MigrationSystem.contextStack.get if (context.isEmpty) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index a1785e5262..69091e4880 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -360,7 +360,7 @@ trait Scanners extends ScannersCommon { if (ch == '"' && token == IDENTIFIER) token = INTERPOLATIONID case '<' => // is XMLSTART? - def fetchLT = { + def fetchLT() = { val last = if (charOffset >= 2) buf(charOffset - 2) else ' ' nextChar() last match { @@ -389,7 +389,7 @@ trait Scanners extends ScannersCommon { getOperatorRest() } case '0' => - def fetchZero = { + def fetchZero() = { putChar(ch) nextChar() if (ch == 'x' || ch == 'X') { @@ -416,7 +416,7 @@ trait Scanners extends ScannersCommon { case '`' => getBackquotedIdent() case '\"' => - def fetchDoubleQuote = { + def fetchDoubleQuote() = { if (token == INTERPOLATIONID) { nextRawChar() if (ch == '\"') { @@ -452,7 +452,7 @@ trait Scanners extends ScannersCommon { } fetchDoubleQuote case '\'' => - def fetchSingleQuote = { + def fetchSingleQuote() = { nextChar() if (isIdentifierStart(ch)) charLitOr(getIdentRest) @@ -500,7 +500,7 @@ trait Scanners extends ScannersCommon { nextChar() } case _ => - def fetchOther = { + def fetchOther() = { if (ch == '\u21D2') { nextChar(); token = ARROW } else if (ch == '\u2190') { diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index 5a5059d58c..4738ad8a38 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -2407,7 +2407,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { (instr.category: @scala.annotation.switch) match { case icodes.localsCat => - def genLocalInstr = (instr: @unchecked) match { + def genLocalInstr() = (instr: @unchecked) match { case THIS(_) => jmethod.visitVarInsn(Opcodes.ALOAD, 0) case LOAD_LOCAL(local) => jcode.load(indexOf(local), local.kind) case STORE_LOCAL(local) => jcode.store(indexOf(local), local.kind) @@ -2440,7 +2440,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genLocalInstr case icodes.stackCat => - def genStackInstr = (instr: @unchecked) match { + def genStackInstr() = (instr: @unchecked) match { case LOAD_MODULE(module) => // assert(module.isModule, "Expected module: " + module) @@ -2468,7 +2468,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { case icodes.arilogCat => genPrimitive(instr.asInstanceOf[CALL_PRIMITIVE].primitive, instr.pos) case icodes.castsCat => - def genCastInstr = (instr: @unchecked) match { + def genCastInstr() = (instr: @unchecked) match { case IS_INSTANCE(tpe) => val jtyp: asm.Type = @@ -2498,7 +2498,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genCastInstr case icodes.objsCat => - def genObjsInstr = (instr: @unchecked) match { + def genObjsInstr() = (instr: @unchecked) match { case BOX(kind) => val MethodNameAndType(mname, mdesc) = jBoxTo(kind) @@ -2518,7 +2518,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genObjsInstr case icodes.fldsCat => - def genFldsInstr = (instr: @unchecked) match { + def genFldsInstr() = (instr: @unchecked) match { case lf @ LOAD_FIELD(field, isStatic) => var owner = javaName(lf.hostClass) @@ -2539,7 +2539,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genFldsInstr case icodes.mthdsCat => - def genMethodsInstr = (instr: @unchecked) match { + def genMethodsInstr() = (instr: @unchecked) match { /** Special handling to access native Array.clone() */ case call @ CALL_METHOD(definitions.Array_clone, Dynamic) => @@ -2552,7 +2552,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genMethodsInstr case icodes.arraysCat => - def genArraysInstr = (instr: @unchecked) match { + def genArraysInstr() = (instr: @unchecked) match { case LOAD_ARRAY_ITEM(kind) => jcode.aload(kind) case STORE_ARRAY_ITEM(kind) => jcode.astore(kind) case CREATE_ARRAY(elem, 1) => jcode newarray elem @@ -2561,7 +2561,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genArraysInstr case icodes.jumpsCat => - def genJumpInstr = (instr: @unchecked) match { + def genJumpInstr() = (instr: @unchecked) match { case sw @ SWITCH(tagss, branches) => assert(branches.length == tagss.length + 1, sw) @@ -2691,7 +2691,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genJumpInstr case icodes.retCat => - def genRetInstr = (instr: @unchecked) match { + def genRetInstr() = (instr: @unchecked) match { case RETURN(kind) => jcode emitRETURN kind case THROW(_) => emit(Opcodes.ATHROW) } @@ -2781,7 +2781,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { case Negation(kind) => jcode.neg(kind) case Arithmetic(op, kind) => - def genArith = { + def genArith() = { op match { case ADD => jcode.add(kind) @@ -2811,7 +2811,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { // TODO GenICode uses `toTypeKind` to define that elem, `toValueTypeKind` would be needed instead. // TODO How about adding some asserts to Logical and similar ones to capture the remaining constraint (UNIT not allowed). case Logical(op, kind) => - def genLogical = op match { + def genLogical() = op match { case AND => kind match { case LONG => emit(Opcodes.LAND) @@ -2840,7 +2840,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genLogical case Shift(op, kind) => - def genShift = op match { + def genShift() = op match { case LSL => kind match { case LONG => emit(Opcodes.LSHL) @@ -2869,7 +2869,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { genShift case Comparison(op, kind) => - def genCompare = op match { + def genCompare() = op match { case CMP => (kind: @unchecked) match { case LONG => emit(Opcodes.LCMP) diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index 07526a5608..86bf1f1efd 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -403,7 +403,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { * This is the final point in the core model creation: no DocTemplates are created after the model has finished, but * inherited templates and implicit members are added to the members at this point. */ - def completeModel: Unit = { + def completeModel(): Unit = { // DFS completion // since alias types and abstract types have no own members, there's no reason for them to call completeModel if (!sym.isAliasType && !sym.isAbstractType) diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index c413448b57..2282f62152 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala @@ -1864,7 +1864,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL def registerEquality(c: Const): Unit // call this to indicate null is part of the domain - def registerNull: Unit + def registerNull(): Unit // can this variable be null? def mayBeNull: Boolean @@ -2279,7 +2279,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL val staticTpCheckable: Type = checkableType(staticTp) private[this] var _mayBeNull = false - def registerNull: Unit = { ensureCanModify; if (NullTp <:< staticTpCheckable) _mayBeNull = true } + def registerNull(): Unit = { ensureCanModify; if (NullTp <:< staticTpCheckable) _mayBeNull = true } def mayBeNull: Boolean = _mayBeNull // case None => domain is unknown, diff --git a/src/library/scala/concurrent/impl/Promise.scala b/src/library/scala/concurrent/impl/Promise.scala index a1a3305db0..ff268d850c 100644 --- a/src/library/scala/concurrent/impl/Promise.scala +++ b/src/library/scala/concurrent/impl/Promise.scala @@ -107,7 +107,7 @@ private[concurrent] object Promise { case _ => None } - override def isCompleted(): Boolean = getState match { // Cheaper than boxing result into Option due to "def value" + override def isCompleted: Boolean = getState match { // Cheaper than boxing result into Option due to "def value" case _: Try[_] => true case _ => false } @@ -156,7 +156,7 @@ private[concurrent] object Promise { val value = Some(resolveTry(suppliedValue)) - override def isCompleted(): Boolean = true + override def isCompleted: Boolean = true def tryComplete(value: Try[T]): Boolean = false |