diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-19 19:21:32 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-19 19:27:11 +0200 |
commit | 4fc9cdb64f577e0561e814377ea0f9747245bbbe (patch) | |
tree | e5d169a110dfe802de665a06a728d124d783f291 | |
parent | d9b65592df28e8c9655b52c0265f499d757617ba (diff) | |
download | scala-4fc9cdb64f577e0561e814377ea0f9747245bbbe.tar.gz scala-4fc9cdb64f577e0561e814377ea0f9747245bbbe.tar.bz2 scala-4fc9cdb64f577e0561e814377ea0f9747245bbbe.zip |
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
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala | 2 | ||||
-rw-r--r-- | test/files/run/t4897.check | 1 | ||||
-rw-r--r-- | test/files/run/t4897.scala | 10 |
3 files changed, 12 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index 4e4176e531..eef2c5fd3c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala @@ -1024,7 +1024,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL else expectedTp match { // TODO: [SPEC] the spec requires `eq` instead of `==` for singleton types // this implies sym.isStable - case SingleType(_, sym) => and(equalsTest(CODE.REF(sym), testedBinder), typeTest(testedBinder, expectedTp.widen)) + case SingleType(_, sym) => and(equalsTest(gen.mkAttributedQualifier(expectedTp), testedBinder), typeTest(testedBinder, expectedTp.widen)) // must use == to support e.g. List() == Nil case ThisType(sym) if sym.isModule => and(equalsTest(CODE.REF(sym), testedBinder), typeTest(testedBinder, expectedTp.widen)) case ConstantType(Constant(null)) if testedBinder.info.widen <:< AnyRefClass.tpe diff --git a/test/files/run/t4897.check b/test/files/run/t4897.check new file mode 100644 index 0000000000..17dda56fe1 --- /dev/null +++ b/test/files/run/t4897.check @@ -0,0 +1 @@ +joepie diff --git a/test/files/run/t4897.scala b/test/files/run/t4897.scala new file mode 100644 index 0000000000..a2ec3de37f --- /dev/null +++ b/test/files/run/t4897.scala @@ -0,0 +1,10 @@ +class CSuper { + object A +} +class C extends CSuper { + def f = (A: AnyRef) match { case _: A.type => "joepie" } +} + +object Test extends C with App { + println(f) +}
\ No newline at end of file |