File tree Expand file tree Collapse file tree 3 files changed +40
-3
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -33,12 +33,13 @@ class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransfo
33
33
34
34
/* Makes a new unique name based on a unique name that was flatten */
35
35
private def refreshedName (sym : Symbol )(implicit ctx : Context ): TypeName = {
36
- // TODO: Refresh names not only based on their full name?
37
- // Include package to distinguish <class>$anon from <pack>.<class>$anon
36
+ val packName = sym.owner.fullName.toString
38
37
val name = sym.name
39
- val newName = (name.firstPart.toString + str.NAME_JOIN + name.lastPart).toTermName
38
+ val newName = (packName + name.firstPart + str.NAME_JOIN + name.lastPart).toTermName
40
39
41
40
var freshName = UniqueName .fresh(newName).toTypeName
41
+ val prefix = if (sym.owner.isEmptyPackage) " $empty$" else packName
42
+ freshName = freshName.toString.substring(prefix.length).toTypeName
42
43
if (name.toSimpleName.endsWith(str.MODULE_SUFFIX ))
43
44
freshName = (freshName + str.MODULE_SUFFIX ).toTypeName
44
45
Original file line number Diff line number Diff line change
1
+ class foo.bar.Foo$$anon$1
2
+ class foo.bar.Foo$$anon$2
3
+ class foo.Foo$$anon$1
4
+ class Foo$$anon$1
Original file line number Diff line number Diff line change
1
+
2
+ object Test {
3
+ def main (args : Array [String ]): Unit = {
4
+ new foo.bar.Foo
5
+ new foo.Foo
6
+ new Foo
7
+ }
8
+ }
9
+
10
+ package foo {
11
+ package bar {
12
+ class Foo {
13
+ new Object {
14
+ println(this .getClass) // Foo$$anon$1
15
+ }
16
+ new Object {
17
+ println(this .getClass) // Foo$$anon$2
18
+ }
19
+ }
20
+ }
21
+ class Foo {
22
+ new Object {
23
+ println(this .getClass) // Foo$$anon$1
24
+ }
25
+ }
26
+ }
27
+
28
+ class Foo {
29
+ new Object {
30
+ println(this .getClass) // Foo$$anon$1
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments