Skip to content

Commit df44b27

Browse files
committed
Merge pull request scala#3638 from xeno-by/topic/freshname-hotfix
SI-8425 don't create double-dollar names in c.freshName
2 parents 79f7e05 + d9687d5 commit df44b27

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/compiler/scala/reflect/macros/contexts/Names.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ trait Names {
3333
//
3434
// TODO: hopefully SI-7823 will provide an ultimate answer to this problem.
3535
// In the meanwhile I will also keep open the original issue: SI-6879 "c.freshName is broken".
36+
val prefix = if (name.endsWith("$")) name else name + "$" // SI-8425
3637
val sortOfUniqueSuffix = freshNameCreator.newName(nme.FRESH_SUFFIX)
37-
name + "$" + sortOfUniqueSuffix
38+
prefix + sortOfUniqueSuffix
3839
}
3940

4041
def freshName[NameType <: Name](name: NameType): NameType =

test/files/run/t8425.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
List(fresh$macro$1, $macro$2)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.language.experimental.macros
2+
import scala.reflect.macros.blackbox.Context
3+
4+
object Macros {
5+
def foo: Unit = macro impl
6+
def impl(c: Context) = {
7+
import c.universe._
8+
val test1 = c.freshName()
9+
val test2 = c.freshName("$")
10+
q"println(List($test1, $test2))"
11+
}
12+
}

test/files/run/t8425/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test extends App {
2+
Macros.foo
3+
}

0 commit comments

Comments
 (0)