Skip to content

Commit

Permalink
Improve static elision of outer tests in pattern matcher
Browse files Browse the repository at this point in the history
When the binder's info is a bounded type, look at the prefix of the
upper bound.

This stops an annoying unchecked warning that appeared since
a recent refactoring made `TermName` a final class. It also avoids
a needless runtime check.
  • Loading branch information
retronym committed Jul 25, 2019
1 parent b5029ab commit 194de04
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,17 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {

override def withOuterTest(orig: Tree)(testedBinder: Symbol, expectedTp: Type): Tree = {
val expectedPrefix = expectedTp.prefix
val testedPrefix = testedBinder.info.prefix
def prefixOf(tp: Type): Type = tp.normalize match {
case RefinedType(parents, _) =>
val temp1 = parents.filterNot(_.typeSymbol.isStatic)
val temp2 = temp1.map(sym => prefixOf(sym))
temp2.distinct match {
case prefix :: Nil => prefix
case _ => NoType
}
case tp => tp.prefix
}
val testedPrefix = prefixOf(abstractTypesToBounds(testedBinder.info))

// Check if a type is defined in a static location. Unlike `tp.isStatic` before `flatten`,
// this also includes methods and (possibly nested) objects inside of methods.
Expand Down
1 change: 1 addition & 0 deletions test/files/pos/t11534.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xfatal-warnings -unchecked
7 changes: 7 additions & 0 deletions test/files/pos/t11534.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test1 {
val g: scala.tools.nsc.Global = ???
import g._
def test(sym: Symbol) = sym.name match {
case _: TermName =>
}
}

0 comments on commit 194de04

Please sign in to comment.