Skip to content

Commit 22bc1f8

Browse files
committed
Merge pull request scala#4095 from retronym/ticket/8933
Fix problems in Symbol Literal static caching
2 parents fad969e + 8d84b62 commit 22bc1f8

File tree

7 files changed

+47
-1
lines changed

7 files changed

+47
-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 =>
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/t8933.check

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

test/files/run/t8933/A_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class MotherClass
2+
3+
trait MixinWithSymbol {
4+
self: MotherClass =>
5+
def symbolFromTrait: Symbol = 'traitSymbol
6+
}

test/files/run/t8933/Test_2.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class MotherClass extends MixinWithSymbol {
2+
val classSymbol = 'classSymbol
3+
}
4+
5+
object Test {
6+
def main(args: Array[String]) {
7+
val symbol = (new MotherClass).symbolFromTrait
8+
println(symbol)
9+
}
10+
}

test/files/run/t8933b/A.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait MixinWithSymbol {
2+
self: MotherClass =>
3+
def symbolFromTrait: Any = 'traitSymbol
4+
}

test/files/run/t8933b/Test.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class MotherClass extends MixinWithSymbol {
2+
def foo = 'sym1
3+
}
4+
5+
object Test {
6+
def main(args: Array[String]) {
7+
(new MotherClass).symbolFromTrait
8+
}
9+
}

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)