diff --git a/compiler/src/dotty/tools/dotc/core/Scopes.scala b/compiler/src/dotty/tools/dotc/core/Scopes.scala index 7df5a7fa3c09..a8855df6a76e 100644 --- a/compiler/src/dotty/tools/dotc/core/Scopes.scala +++ b/compiler/src/dotty/tools/dotc/core/Scopes.scala @@ -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) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 48559787c6a1..87d8ef0e41e4 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -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 @@ -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 diff --git a/tests/neg/i19506.scala b/tests/neg/i19506.scala index 0d3f9770a7ae..1b877a0bae7d 100644 --- a/tests/neg/i19506.scala +++ b/tests/neg/i19506.scala @@ -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 = ??? diff --git a/tests/pos/i19530.scala b/tests/pos/i19530.scala new file mode 100644 index 000000000000..01c3cc50a12d --- /dev/null +++ b/tests/pos/i19530.scala @@ -0,0 +1,3 @@ +object A { + def x = classOf[scala.Singleton] +} \ No newline at end of file