summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-09-09 16:59:43 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-09-09 18:20:01 +0200
commit24b0711f01dcb410ffd0454881f7a96073f92e16 (patch)
treeda48f345062d67de9a6a344db556253d1d864bbc /src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
parentadf2d3632b07eef4fc2303aef994e66584a73f49 (diff)
downloadscala-24b0711f01dcb410ffd0454881f7a96073f92e16.tar.gz
scala-24b0711f01dcb410ffd0454881f7a96073f92e16.tar.bz2
scala-24b0711f01dcb410ffd0454881f7a96073f92e16.zip
SI-6276 Warn on def or val that trivially loops infinitely
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/RefChecks.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 166bb2d18c..dd4f13fd7b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1197,6 +1197,18 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
case _ =>
}
+ // SI-6276 warn for `def foo = foo` or `val bar: X = bar`, which come up more frequently than you might think.
+ def checkInfiniteLoop(valOrDef: ValOrDefDef) {
+ val trivialInifiniteLoop = (
+ !valOrDef.isErroneous
+ && !valOrDef.symbol.isValueParameter
+ && valOrDef.symbol.paramss.isEmpty
+ && valOrDef.rhs.hasSymbolWhich(_.accessedOrSelf == valOrDef.symbol)
+ )
+ if (trivialInifiniteLoop)
+ unit.warning(valOrDef.rhs.pos, s"${valOrDef.symbol.fullLocationString} does nothing other than call itself recursively")
+ }
+
// Transformation ------------------------------------------------------------
/* Convert a reference to a case factory of type `tpe` to a new of the class it produces. */
@@ -1640,6 +1652,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
case ValDef(_, _, _, _) | DefDef(_, _, _, _, _, _) =>
checkDeprecatedOvers(tree)
+ checkInfiniteLoop(tree.asInstanceOf[ValOrDefDef])
if (settings.warnNullaryUnit.value)
checkNullaryMethodReturnType(sym)
if (settings.warnInaccessible.value) {