diff --git a/compiler/src/dotty/tools/dotc/core/Scopes.scala b/compiler/src/dotty/tools/dotc/core/Scopes.scala index cb5f5c55e337..b22ce84849c1 100644 --- a/compiler/src/dotty/tools/dotc/core/Scopes.scala +++ b/compiler/src/dotty/tools/dotc/core/Scopes.scala @@ -257,10 +257,6 @@ object Scopes { e } - /** create and enter a scope entry */ - protected def newScopeEntry(sym: Symbol)(using Context): ScopeEntry = - newScopeEntry(sym.name, sym) - private def enterInHash(e: ScopeEntry)(using Context): Unit = { val idx = e.name.hashCode & (hashTable.length - 1) e.tail = hashTable(idx) @@ -273,7 +269,11 @@ object Scopes { if (sym.isType && ctx.phaseId <= typerPhase.id) assert(lookup(sym.name) == NoSymbol, s"duplicate ${sym.debugString}; previous was ${lookup(sym.name).debugString}") // !!! DEBUG - newScopeEntry(sym) + enter(sym.name, sym) + } + + final def enter[T <: Symbol](name: Name, sym: T)(using Context): T = { + newScopeEntry(name, sym) sym } @@ -375,7 +375,7 @@ object Scopes { } if ((e eq null) && (synthesize != null)) { val sym = synthesize(name) - if (sym.exists) newScopeEntry(sym) else e + if (sym.exists) newScopeEntry(sym.name, sym) else e } else e } diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 3a077407d0b5..7e89b4e2c2c9 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -654,7 +654,14 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst tr1 :: trs1.filterNot(_.isAnyRef) case nil => nil } - val erasedDecls = decls.filteredScope(sym => !sym.isType || sym.isClass) + var erasedDecls = decls.filteredScope(sym => !sym.isType || sym.isClass).openForMutations + for dcl <- erasedDecls.iterator do + if dcl.lastKnownDenotation.unforcedAnnotation(defn.TargetNameAnnot).isDefined + && dcl.targetName != dcl.name + then + if erasedDecls eq decls then erasedDecls = erasedDecls.cloneScope + erasedDecls.unlink(dcl) + erasedDecls.enter(dcl.targetName, dcl) val selfType1 = if cls.is(Module) then cls.sourceModule.termRef else NoType tp.derivedClassInfo(NoPrefix, erasedParents, erasedDecls, selfType1) // can't replace selftype by NoType because this would lose the sourceModule link diff --git a/tests/run/i13252a.scala b/tests/run/i13252a.scala new file mode 100644 index 000000000000..d12706f62a95 --- /dev/null +++ b/tests/run/i13252a.scala @@ -0,0 +1,12 @@ +object Test: + + class Star + + trait Foo: + @annotation.targetName("star") + val * : Star = new Star + + object Bar extends Foo + + def main(sa: Array[String]): Unit = + Bar.* \ No newline at end of file diff --git a/tests/run/i13252b/Foo_1.scala b/tests/run/i13252b/Foo_1.scala new file mode 100644 index 000000000000..7e7551e14f4c --- /dev/null +++ b/tests/run/i13252b/Foo_1.scala @@ -0,0 +1,5 @@ +class Star + +trait Foo: + @annotation.targetName("star") + val * : Star = new Star diff --git a/tests/run/i13252b/Test_2.scala b/tests/run/i13252b/Test_2.scala new file mode 100644 index 000000000000..b4d382d2cc1f --- /dev/null +++ b/tests/run/i13252b/Test_2.scala @@ -0,0 +1,6 @@ +object Test: + + object Bar extends Foo + + def main(sa: Array[String]): Unit = + Bar.* \ No newline at end of file