Skip to content

Commit 1c61bdf

Browse files
committed
Use local fresh indices for lifted classes in diferent packages
1 parent 8d485ba commit 1c61bdf

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransfo
3333

3434
/* Makes a new unique name based on a unique name that was flatten */
3535
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
3837
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
4039

4140
var freshName = UniqueName.fresh(newName).toTypeName
41+
val prefix = if (sym.owner.isEmptyPackage) "$empty$" else packName
42+
freshName = freshName.toString.substring(prefix.length).toTypeName
4243
if (name.toSimpleName.endsWith(str.MODULE_SUFFIX))
4344
freshName = (freshName + str.MODULE_SUFFIX).toTypeName
4445

tests/run/i2964e.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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

tests/run/i2964e.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

tests/run/i3000b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Foo$$anon$1
2-
bar.Bar$$anon$2
2+
bar.Bar$$anon$1

0 commit comments

Comments
 (0)