Skip to content

Commit

Permalink
SI-7974 Fix over-eager optimization of Symbol literals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
retronym committed Nov 7, 2014
1 parent 33393c7 commit 8d84b62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/transform/CleanUp.scala
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions 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

0 comments on commit 8d84b62

Please sign in to comment.