diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala index 4a6731744dcd..c960d7028239 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala @@ -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. diff --git a/test/files/pos/t11534.flags b/test/files/pos/t11534.flags new file mode 100644 index 000000000000..b5a874865273 --- /dev/null +++ b/test/files/pos/t11534.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked diff --git a/test/files/pos/t11534.scala b/test/files/pos/t11534.scala new file mode 100644 index 000000000000..2e36dfec5b73 --- /dev/null +++ b/test/files/pos/t11534.scala @@ -0,0 +1,7 @@ +object Test1 { + val g: scala.tools.nsc.Global = ??? + import g._ + def test(sym: Symbol) = sym.name match { + case _: TermName => + } +}