Skip to content

Commit 20d2f89

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

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

+4-4
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(symbol = copy, 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) =

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class BootstrappedOnlyCompilationTests {
150150

151151
@Test def picklingWithCompiler: Unit = {
152152
val jvmBackendFilter = FileFilter.exclude(List("BTypes.scala", "Primitives.scala")) // TODO
153-
val runtimeFilter = FileFilter.exclude(List("Tuple.scala", "stdLibPatches")) // TODO
153+
val runtimeFilter = FileFilter.exclude(List("Tuple.scala")) // TODO
154154
implicit val testGroup: TestGroup = TestGroup("testPicklingWithCompiler")
155155
aggregateTests(
156156
compileDir("compiler/src/dotty/tools", picklingWithCompilerOptions, recursive = false),

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

+15
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
@@ -49,13 +54,15 @@ object language:
4954
* Features in this object are slated for removal. New code should not use them and
5055
* old code should migrate away from them.
5156
*/
57+
@compileTimeOnly("`deprecated` can only be used at compile time in import statements")
5258
object deprecated:
5359

5460
/** Symbol literals have been deprecated since 2.13. Since Scala 3.0 they
5561
* are no longer an official part of Scala. For compatibility with legacy software,
5662
* symbol literals are still supported with a language import, but new software
5763
* should not use them.
5864
*/
65+
@compileTimeOnly("`symbolLiterals` can only be used at compile time in import statements")
5966
object symbolLiterals
6067
end deprecated
6168

@@ -69,6 +76,7 @@ object language:
6976
* '''Why allow it?''' Not allowing auto-tupling is difficult to reconcile with
7077
* operators accepting tuples.
7178
*/
79+
@compileTimeOnly("`noAutoTupling` can only be used at compile time in import statements")
7280
object noAutoTupling
7381

7482
/** Where imported, loose equality using eqAny is disabled.
@@ -78,6 +86,7 @@ object language:
7886
*
7987
* @see [[https://dotty.epfl.ch/docs/reference/contextual/multiversal-equality]]
8088
*/
89+
@compileTimeOnly("`strictEquality` can only be used at compile time in import statements")
8190
object strictEquality
8291

8392
/** Where imported, ad hoc extensions of non-open classes in other
@@ -96,29 +105,35 @@ object language:
96105
* such extensions should be limited in scope and clearly documented.
97106
* That's why the language import is required for them.
98107
*/
108+
@compileTimeOnly("`adhocExtensions` can only be used at compile time in import statements")
99109
object adhocExtensions
100110

101111
/** Unsafe Nulls fot Explicit Nulls
102112
* Inside the "unsafe" scope, `Null` is considered as a subtype of all reference types.
103113
*
104114
* @see [[http://dotty.epfl.ch/docs/reference/other-new-features/explicit-nulls.html]]
105115
*/
116+
@compileTimeOnly("`unsafeNulls` can only be used at compile time in import statements")
106117
object unsafeNulls
107118

119+
@compileTimeOnly("`future` can only be used at compile time in import statements")
108120
object future
109121

122+
@compileTimeOnly("`future-migration` can only be used at compile time in import statements")
110123
object `future-migration`
111124

112125
/** Set source version to 3.0-migration.
113126
*
114127
* @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]]
115128
*/
129+
@compileTimeOnly("`3.0-migration` can only be used at compile time in import statements")
116130
object `3.0-migration`
117131

118132
/** Set source version to 3.0.
119133
*
120134
* @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]]
121135
*/
136+
@compileTimeOnly("`3.0` can only be used at compile time in import statements")
122137
object `3.0`
123138

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

0 commit comments

Comments
 (0)