summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Infer.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-08-20 10:25:28 -0700
committerSom Snytt <som.snytt@gmail.com>2014-09-05 01:07:44 -0700
commitc9ec916f20c4f06a0aebe0a9929443c1c8b60c5c (patch)
tree9c592c054af335510d57fa2ff3fc0e733f8953a1 /src/compiler/scala/tools/nsc/typechecker/Infer.scala
parentd4b5c7b95de88d3890be654e06da812c6eb607f5 (diff)
downloadscala-c9ec916f20c4f06a0aebe0a9929443c1c8b60c5c.tar.gz
scala-c9ec916f20c4f06a0aebe0a9929443c1c8b60c5c.tar.bz2
scala-c9ec916f20c4f06a0aebe0a9929443c1c8b60c5c.zip
SI-8806 Add lower bound check to Any lint
We already exclude the lint check for infer-any if Any is somewhere explicit. This commit adds lower bounds of type params to the somewheres. Motivated by: ``` scala> f"${42}" <console>:8: warning: a type was inferred to be `Any`; this may indicate a programming error. f"${42}" ^ res0: String = 42 ```
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Infer.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index a3f1da60ce..c793632de4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -546,7 +546,14 @@ trait Infer extends Checkable {
val targs = solvedTypes(tvars, tparams, tparams map varianceInTypes(formals), upper = false, lubDepth(formals) max lubDepth(argtpes))
// Can warn about inferring Any/AnyVal as long as they don't appear
// explicitly anywhere amongst the formal, argument, result, or expected type.
- def canWarnAboutAny = !(pt :: restpe :: formals ::: argtpes exists (t => (t contains AnyClass) || (t contains AnyValClass)))
+ // ...or lower bound of a type param, since they're asking for it.
+ def canWarnAboutAny = {
+ val loBounds = tparams map (_.info.bounds.lo)
+ val hasAny = pt :: restpe :: formals ::: argtpes ::: loBounds exists (t =>
+ (t contains AnyClass) || (t contains AnyValClass)
+ )
+ !hasAny
+ }
def argumentPosition(idx: Int): Position = context.tree match {
case x: ValOrDefDef => x.rhs match {
case Apply(fn, args) if idx < args.size => args(idx).pos
@@ -554,7 +561,7 @@ trait Infer extends Checkable {
}
case _ => context.tree.pos
}
- if (settings.warnInferAny.value && context.reportErrors && canWarnAboutAny) {
+ if (settings.warnInferAny && context.reportErrors && canWarnAboutAny) {
foreachWithIndex(targs) ((targ, idx) =>
targ.typeSymbol match {
case sym @ (AnyClass | AnyValClass) =>