From 8d84b62fc9ca2bc01c7e3119088ddac185695124 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 6 Nov 2014 15:18:41 +1000 Subject: SI-7974 Fix over-eager optimization of Symbol literals A classic mistake of discarding a non-trivial qualifier. We actually should have fixed this before merging #3149, as it was raised in review, but I suppose we got too caught up in the difficulty of resolving the right overload of `Symbol_apply` that we forgot. --- src/compiler/scala/tools/nsc/transform/CleanUp.scala | 4 +++- test/files/run/t8933c.scala | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/files/run/t8933c.scala diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index e5a19205ae..c29826551b 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -520,7 +520,9 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL { * And, finally, be advised - Scala's Symbol literal (scala.Symbol) and the Symbol class of the compiler * have little in common. */ - case Apply(fn, (arg @ Literal(Constant(symname: String))) :: Nil) if fn.symbol == Symbol_apply && !currentClass.isTrait => + case Apply(fn @ Select(qual, _), (arg @ Literal(Constant(symname: String))) :: Nil) + if treeInfo.isQualifierSafeToElide(qual) && fn.symbol == Symbol_apply && !currentClass.isTrait => + def transformApply = { // add the symbol name to a map if it's not there already val rhs = gen.mkMethodCall(Symbol_apply, arg :: Nil) diff --git a/test/files/run/t8933c.scala b/test/files/run/t8933c.scala new file mode 100644 index 0000000000..22011bc323 --- /dev/null +++ b/test/files/run/t8933c.scala @@ -0,0 +1,14 @@ +object Test { + def main(args: Array[String]): Unit = { + try { + {throw T; Symbol}.apply("a") + assert(false, "exception not thrown") + } catch { + case T => // ok + case t: Throwable => + assert(false, "wrong not thrown: " + t) + } + } +} + +object T extends Throwable -- cgit v1.2.3