Skip to content

Commit a33db77

Browse files
committed
Fix #11654: create new symbol for stdlib patches
1 parent 422ffbc commit a33db77

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ package core
55
import scala.annotation.{threadUnsafe => tu}
66
import Types._, Contexts._, Symbols._, SymDenotations._, StdNames._, Names._, Phases._
77
import Flags._, Scopes._, Decorators._, NameOps._, Periods._, NullOpsDecorator._
8+
import ast.tpd.Literal, Constants.Constant
89
import unpickleScala2.Scala2Unpickler.ensureConstructor
910
import scala.collection.mutable
1011
import collection.mutable
1112
import Denotations.SingleDenotation
1213
import util.{SimpleIdentityMap, SourceFile, NoSource}
1314
import typer.ImportInfo.RootRef
15+
import Annotations.Annotation
1416

1517
import scala.annotation.tailrec
1618

@@ -1108,6 +1110,9 @@ class Definitions {
11081110
* is read from a classfile.
11091111
*/
11101112
def patchStdLibClass(denot: ClassDenotation)(using Context): Unit =
1113+
val annot = Annotation.deferredSymAndTree(defn.CompileTimeOnlyAnnot) {
1114+
Literal(Constant("The symbol can only be used at compile time in import statements"))
1115+
}
11111116

11121117
def patch2(denot: ClassDenotation, patchCls: Symbol): Unit =
11131118
val scope = denot.info.decls.openForMutations
@@ -1121,9 +1126,11 @@ class Definitions {
11211126
for patch <- patches do
11221127
patch.ensureCompleted()
11231128
if !recurse(patch) then
1124-
patch.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1125-
scope.enter(patch)
1126-
else if patch.isClass then
1129+
val copy = patch.copy(owner = denot.symbol)
1130+
copy.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1131+
copy.addAnnotation(annot)
1132+
scope.enter(copy)
1133+
if patch.isClass then
11271134
patch2(scope.lookup(patch.name).asClass, patch)
11281135

11291136
def patchWith(patchCls: Symbol) =

0 commit comments

Comments
 (0)