diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-22 11:11:41 -0800 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-01-22 11:11:41 -0800 |
commit | f22ddce265e8622e95f5e9cab4d38168bf2c3bf8 (patch) | |
tree | e6edeca6613a569350f26780ae61ab5b780f7c7b /src/compiler | |
parent | 7a23a908a77e2424c0f951acb3f0de6a0cac454c (diff) | |
parent | 56d980c830ef9fc4c901a8c4b8e4b9c42adb49b4 (diff) | |
download | scala-f22ddce265e8622e95f5e9cab4d38168bf2c3bf8.tar.gz scala-f22ddce265e8622e95f5e9cab4d38168bf2c3bf8.tar.bz2 scala-f22ddce265e8622e95f5e9cab4d38168bf2c3bf8.zip |
Merge pull request #3401 from xeno-by/topic/fresh
SI-6879 improves Context.freshName
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/macros/contexts/Names.scala | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/compiler/scala/reflect/macros/contexts/Names.scala b/src/compiler/scala/reflect/macros/contexts/Names.scala index c2f14cf0f1..299af40b94 100644 --- a/src/compiler/scala/reflect/macros/contexts/Names.scala +++ b/src/compiler/scala/reflect/macros/contexts/Names.scala @@ -4,7 +4,9 @@ package contexts trait Names { self: Context => - def freshNameCreator = callsiteTyper.context.unit.fresh + import global._ + + def freshNameCreator = globalFreshNameCreator def fresh(): String = freshName() @@ -16,11 +18,25 @@ trait Names { freshName[NameType](name) def freshName(): String = - freshName("fresh$") - - def freshName(name: String): String = - freshNameCreator.newName(name) + freshName(nme.FRESH_PREFIX) + + def freshName(name: String): String = { + // In comparison with the first version of freshName, current "fresh" names + // at least can't clash with legible user-written identifiers and are much less likely to clash with each other. + // It is still not good enough however, because the counter gets reset every time we create a new Global. + // + // This would most certainly cause problems if Scala featured something like introduceTopLevel, + // but even for def macros this can lead to unexpected troubles. Imagine that one Global + // creates a term of an anonymous type with a member featuring a "fresh" name, and then another Global + // imports that term with a wildcard and then generates a "fresh" name of its own. Given unlucky + // circumstances these "fresh" names might end up clashing. + // + // TODO: hopefully SI-7823 will provide an ultimate answer to this problem. + // In the meanwhile I will also keep open the original issue: SI-6879 "c.freshName is broken". + val sortOfUniqueSuffix = freshNameCreator.newName(nme.FRESH_SUFFIX) + name + "$" + sortOfUniqueSuffix + } def freshName[NameType <: Name](name: NameType): NameType = - name.mapName(freshNameCreator.newName(_)).asInstanceOf[NameType] + name.mapName(freshName(_)).asInstanceOf[NameType] }
\ No newline at end of file |