Skip to content

Make eraseInfo work for classes with empty scopes #19553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ object Scopes {

def implicitDecls(using Context): List[TermRef] = Nil

def openForMutations: MutableScope = unsupported("openForMutations")
def openForMutations: MutableScope = unsupported(s"openForMutations $this")

final def toText(printer: Printer): Text = printer.toText(this)

Expand Down
22 changes: 13 additions & 9 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,17 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
tr1 :: trs1.filterNot(_.isAnyRef)
case nil => nil
}
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)
var erasedDecls = decls.filteredScope(sym => !sym.isType || sym.isClass)
if !erasedDecls.isEmpty then
var eds = erasedDecls.openForMutations
for dcl <- eds.iterator do
if dcl.lastKnownDenotation.unforcedAnnotation(defn.TargetNameAnnot).isDefined
&& dcl.targetName != dcl.name
then
if eds eq decls then eds = eds.cloneScope
eds.unlink(dcl)
eds.enter(dcl.targetName, dcl)
erasedDecls = eds
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 Expand Up @@ -814,7 +817,8 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
eraseResult(tp1.resultType) match
case rt: MethodType => rt
case rt => MethodType(Nil, Nil, rt)
case tp1 => this(tp1)
case tp1 =>
this(tp1)

private def eraseDerivedValueClass(tp: Type)(using Context): Type = {
val cls = tp.classSymbol.asClass
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i19506.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options "-source:3.4-migration",
//> using options -source 3.4-migration

trait Reader[T]
def read[T: Reader](s: String, trace: Boolean = false): T = ???
Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i19530.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object A {
def x = classOf[scala.Singleton]
}