Skip to content

Commit

Permalink
Merge pull request #8706 from som-snytt/revert/reversion
Browse files Browse the repository at this point in the history
Restore warn-any improvement
  • Loading branch information
lrytz committed Feb 12, 2020
2 parents d7cfc0b + 0894cd3 commit f573c4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 14 additions & 5 deletions src/compiler/scala/tools/nsc/typechecker/Infer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
package scala.tools.nsc
package typechecker

import scala.collection.mutable.ListBuffer
import scala.collection.{immutable, mutable}
import scala.collection.{immutable, mutable}, mutable.ListBuffer
import scala.reflect.internal.Depth
import scala.util.control.ControlThrowable
import symtab.Flags._
import scala.reflect.internal.Depth

/** This trait contains methods related to type parameter inference.
*
Expand Down Expand Up @@ -589,8 +588,18 @@ trait Infer extends Checkable {
// ...or lower bound of a type param, since they're asking for it.
var checked, warning = false
def checkForAny(): Unit = {
val collector = new ContainsAnyCollector(topTypes)
@`inline` def containsAny(t: Type) = t.dealiasWidenChain.exists(collector.collect)
val collector = new ContainsAnyCollector(topTypes) {
val seen = mutable.Set.empty[Type]
override def apply(t: Type): Unit = {
def saw(dw: Type): Unit =
if (!result && !seen(dw)) {
seen += dw
if (!dw.typeSymbol.isRefinementClass) super.apply(dw)
}
if (!result && !seen(t)) t.dealiasWidenChain.foreach(saw)
}
}
@`inline` def containsAny(t: Type) = collector.collect(t)
val hasAny = containsAny(pt) || containsAny(restpe) ||
formals.exists(containsAny) ||
argtpes.exists(containsAny) ||
Expand Down
5 changes: 1 addition & 4 deletions test/files/neg/warn-inferred-any.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ warn-inferred-any.scala:27: warning: a type was inferred to be `Any`; this may i
warn-inferred-any.scala:37: warning: a type was inferred to be `Object`; this may indicate a programming error.
cs.contains(new C2) // warns
^
warn-inferred-any.scala:52: warning: a type was inferred to be `Any`; this may indicate a programming error.
stream.mapM(f) // should not warn
^
error: No warnings can be incurred under -Werror.
6 warnings
5 warnings
1 error

0 comments on commit f573c4e

Please sign in to comment.