Skip to content

Commit 4fc9cdb

Browse files
author
Adriaan Moors
committed
SI-4897 derive expected value from single type
when the type in a type test is, say, `C.this.A.type`, must use the corresponding term `C.this.A` to test for equality if you use the naive REF(<C.this.A.type>.symbol), you'll get a path like `OwnerOfA.this.A`, where `OwnerOfA` might be a superclass of `C`, and explicitouter won't like that
1 parent d9b6559 commit 4fc9cdb

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
10241024
else expectedTp match {
10251025
// TODO: [SPEC] the spec requires `eq` instead of `==` for singleton types
10261026
// this implies sym.isStable
1027-
case SingleType(_, sym) => and(equalsTest(CODE.REF(sym), testedBinder), typeTest(testedBinder, expectedTp.widen))
1027+
case SingleType(_, sym) => and(equalsTest(gen.mkAttributedQualifier(expectedTp), testedBinder), typeTest(testedBinder, expectedTp.widen))
10281028
// must use == to support e.g. List() == Nil
10291029
case ThisType(sym) if sym.isModule => and(equalsTest(CODE.REF(sym), testedBinder), typeTest(testedBinder, expectedTp.widen))
10301030
case ConstantType(Constant(null)) if testedBinder.info.widen <:< AnyRefClass.tpe

test/files/run/t4897.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
joepie

test/files/run/t4897.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CSuper {
2+
object A
3+
}
4+
class C extends CSuper {
5+
def f = (A: AnyRef) match { case _: A.type => "joepie" }
6+
}
7+
8+
object Test extends C with App {
9+
println(f)
10+
}

0 commit comments

Comments
 (0)