Skip to content

Commit 224a0da

Browse files
committed
Fix #11654: create new symbol for stdlib patches
1 parent 6de2883 commit 224a0da

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,6 +5,7 @@ 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
@@ -14,6 +15,7 @@ import typer.ImportInfo.RootRef
1415
import Comments.CommentsContext
1516
import Comments.Comment
1617
import util.Spans.NoSpan
18+
import Annotations.Annotation
1719

1820
import scala.annotation.tailrec
1921

@@ -1111,6 +1113,9 @@ class Definitions {
11111113
* is read from a classfile.
11121114
*/
11131115
def patchStdLibClass(denot: ClassDenotation)(using Context): Unit =
1116+
val annot = Annotation.deferredSymAndTree(defn.CompileTimeOnlyAnnot) {
1117+
Literal(Constant("The symbol can only be used at compile time in import statements"))
1118+
}
11141119

11151120
def patch2(denot: ClassDenotation, patchCls: Symbol): Unit =
11161121
val scope = denot.info.decls.openForMutations
@@ -1124,9 +1129,11 @@ class Definitions {
11241129
for patch <- patches do
11251130
patch.ensureCompleted()
11261131
if !recurse(patch) then
1127-
patch.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1128-
scope.enter(patch)
1129-
else if patch.isClass then
1132+
val copy = patch.copy(owner = denot.symbol)
1133+
copy.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1134+
copy.addAnnotation(annot)
1135+
scope.enter(copy)
1136+
if patch.isClass then
11301137
patch2(scope.lookup(patch.name).asClass, patch)
11311138

11321139
def patchWith(patchCls: Symbol) =

0 commit comments

Comments
 (0)