Skip to content

Commit 8d84b62

Browse files
committed
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 scala#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.
1 parent 33393c7 commit 8d84b62

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/compiler/scala/tools/nsc/transform/CleanUp.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
520520
* And, finally, be advised - Scala's Symbol literal (scala.Symbol) and the Symbol class of the compiler
521521
* have little in common.
522522
*/
523-
case Apply(fn, (arg @ Literal(Constant(symname: String))) :: Nil) if fn.symbol == Symbol_apply && !currentClass.isTrait =>
523+
case Apply(fn @ Select(qual, _), (arg @ Literal(Constant(symname: String))) :: Nil)
524+
if treeInfo.isQualifierSafeToElide(qual) && fn.symbol == Symbol_apply && !currentClass.isTrait =>
525+
524526
def transformApply = {
525527
// add the symbol name to a map if it's not there already
526528
val rhs = gen.mkMethodCall(Symbol_apply, arg :: Nil)

test/files/run/t8933c.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
try {
4+
{throw T; Symbol}.apply("a")
5+
assert(false, "exception not thrown")
6+
} catch {
7+
case T => // ok
8+
case t: Throwable =>
9+
assert(false, "wrong not thrown: " + t)
10+
}
11+
}
12+
}
13+
14+
object T extends Throwable

0 commit comments

Comments
 (0)