Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var erasedDecls = decls.filteredScope(sym => !sym.isType || sym.isClass).openForMutations
var erasedDecls = decls.filteredScope(sym => !sym.isType || sym.isClass)

? (see comment below)

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
Expand Down
12 changes: 12 additions & 0 deletions tests/run/i13252a.scala
Original file line number Diff line number Diff line change
@@ -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.*
5 changes: 5 additions & 0 deletions tests/run/i13252b/Foo_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Star

trait Foo:
@annotation.targetName("star")
val * : Star = new Star
6 changes: 6 additions & 0 deletions tests/run/i13252b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Test:

object Bar extends Foo

def main(sa: Array[String]): Unit =
Bar.*