Skip to content

Commit 502ad0f

Browse files
authored
Merge pull request scala#7793 from diesalbla/extract_top_types_collector
Extract the ContainsAnyCollector object out of loop.
2 parents 2c32023 + 42bfef0 commit 502ad0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/Infer.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ trait Infer extends Checkable {
560560
// explicitly anywhere amongst the formal, argument, result, or expected type.
561561
// ...or lower bound of a type param, since they're asking for it.
562562
def canWarnAboutAny = {
563-
val coll = new ContainsAnyCollector(List(AnyClass, AnyValClass, ObjectClass))
563+
val coll = new ContainsAnyCollector(topTypes)
564564
def containsAny(t: Type) = t.dealiasWidenChain.exists(coll.collect)
565565
val hasAny = containsAny(pt) || containsAny(restpe) ||
566566
formals.exists(containsAny) ||
@@ -570,7 +570,7 @@ trait Infer extends Checkable {
570570
}
571571
if (settings.warnInferAny && context.reportErrors && !fn.isEmpty && canWarnAboutAny) {
572572
targs.foreach(_.typeSymbol match {
573-
case sym @ (AnyClass | AnyValClass | ObjectClass) =>
573+
case sym if topTypes contains sym =>
574574
reporter.warning(fn.pos, s"a type was inferred to be `${sym.name}`; this may indicate a programming error.")
575575
case _ =>
576576
})
@@ -1515,6 +1515,8 @@ trait Infer extends Checkable {
15151515
}
15161516
}
15171517

1518+
private lazy val topTypes: List[Symbol] = List(AnyClass, AnyValClass, ObjectClass)
1519+
15181520
/** [Martin] Can someone comment this please? I have no idea what it's for
15191521
* and the code is not exactly readable.
15201522
*/

0 commit comments

Comments
 (0)