Skip to content

Commit 062d47e

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

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,6 @@ class Definitions {
11111111
* is read from a classfile.
11121112
*/
11131113
def patchStdLibClass(denot: ClassDenotation)(using Context): Unit =
1114-
11151114
def patch2(denot: ClassDenotation, patchCls: Symbol): Unit =
11161115
val scope = denot.info.decls.openForMutations
11171116
def recurse(patch: Symbol) = patch.is(Module) && scope.lookup(patch.name).exists
@@ -1124,9 +1123,10 @@ class Definitions {
11241123
for patch <- patches do
11251124
patch.ensureCompleted()
11261125
if !recurse(patch) then
1127-
patch.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1128-
scope.enter(patch)
1129-
else if patch.isClass then
1126+
val copy = patch.copy(owner = denot.symbol)
1127+
copy.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1128+
scope.enter(copy)
1129+
if patch.isClass then
11301130
patch2(scope.lookup(patch.name).asClass, patch)
11311131

11321132
def patchWith(patchCls: Symbol) =

library/src/scala/runtime/stdLibPatches/language.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package scala.runtime.stdLibPatches
22

3+
import scala.annotation.compileTimeOnly
4+
35
/** Scala 3 additions and replacements to the `scala.language` object.
46
*/
57
object language:
@@ -29,18 +31,21 @@ object language:
2931
*
3032
* @see [[https://dotty.epfl.ch/docs/reference/other-new-features/named-typeargs]]
3133
*/
34+
@compileTimeOnly("`namedTypeArguments` can only be used at compile time in import statements")
3235
object namedTypeArguments
3336

3437
/** Experimental support for generic number literals.
3538
*
3639
* @see [[https://dotty.epfl.ch/docs/reference/changed-features/numeric-literals]]
3740
*/
41+
@compileTimeOnly("`genericNumberLiterals` can only be used at compile time in import statements")
3842
object genericNumberLiterals
3943

4044
/** Experimental support for `erased` modifier
4145
*
4246
* @see [[https://dotty.epfl.ch/docs/reference/experimental/erased-defs]]
4347
*/
48+
@compileTimeOnly("`erasedDefinitions` can only be used at compile time in import statements")
4449
object erasedDefinitions
4550

4651
end experimental
@@ -56,6 +61,7 @@ object language:
5661
* symbol literals are still supported with a language import, but new software
5762
* should not use them.
5863
*/
64+
@compileTimeOnly("`symbolLiterals` can only be used at compile time in import statements")
5965
object symbolLiterals
6066
end deprecated
6167

@@ -69,6 +75,7 @@ object language:
6975
* '''Why allow it?''' Not allowing auto-tupling is difficult to reconcile with
7076
* operators accepting tuples.
7177
*/
78+
@compileTimeOnly("`noAutoTupling` can only be used at compile time in import statements")
7279
object noAutoTupling
7380

7481
/** Where imported, loose equality using eqAny is disabled.
@@ -78,6 +85,7 @@ object language:
7885
*
7986
* @see [[https://dotty.epfl.ch/docs/reference/contextual/multiversal-equality]]
8087
*/
88+
@compileTimeOnly("`strictEquality` can only be used at compile time in import statements")
8189
object strictEquality
8290

8391
/** Where imported, ad hoc extensions of non-open classes in other
@@ -96,29 +104,35 @@ object language:
96104
* such extensions should be limited in scope and clearly documented.
97105
* That's why the language import is required for them.
98106
*/
107+
@compileTimeOnly("`adhocExtensions` can only be used at compile time in import statements")
99108
object adhocExtensions
100109

101110
/** Unsafe Nulls fot Explicit Nulls
102111
* Inside the "unsafe" scope, `Null` is considered as a subtype of all reference types.
103112
*
104113
* @see [[http://dotty.epfl.ch/docs/reference/other-new-features/explicit-nulls.html]]
105114
*/
115+
@compileTimeOnly("`unsafeNulls` can only be used at compile time in import statements")
106116
object unsafeNulls
107117

118+
@compileTimeOnly("`future` can only be used at compile time in import statements")
108119
object future
109120

121+
@compileTimeOnly("`future-migration` can only be used at compile time in import statements")
110122
object `future-migration`
111123

112124
/** Set source version to 3.0-migration.
113125
*
114126
* @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]]
115127
*/
128+
@compileTimeOnly("`3.0-migration` can only be used at compile time in import statements")
116129
object `3.0-migration`
117130

118131
/** Set source version to 3.0.
119132
*
120133
* @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]]
121134
*/
135+
@compileTimeOnly("`3.0` can only be used at compile time in import statements")
122136
object `3.0`
123137

124138
/* This can be added when we go to 3.1

0 commit comments

Comments
 (0)