diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 699164240015..865fc7a1e442 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -397,6 +397,7 @@ private sealed trait YSettings: val Ylog: Setting[List[String]] = PhasesSetting(ForkSetting, "Ylog", "Log operations during") val YlogClasspath: Setting[Boolean] = BooleanSetting(ForkSetting, "Ylog-classpath", "Output information about what classpath is being applied.") val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting(ForkSetting, "YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.") + val YnoStdlibPatches: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-stdlib-patches", "Do not patch stdlib files (temporary and only to be used for the stdlib migration)", false) val Yscala2Unpickler: Setting[String] = StringSetting(ForkSetting, "Yscala2-unpickler", "", "Control where we may get Scala 2 symbols from. This is either \"always\", \"never\", or a classpath.", "always") diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 381caa775dbd..d8433de44cb5 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1468,6 +1468,11 @@ class Definitions { * is read from a classfile. */ def patchStdLibClass(denot: ClassDenotation)(using Context): Unit = + // Do not patch the stdlib files if we explicitly disable it + // This is only to be used during the migration of the stdlib + if ctx.settings.YnoStdlibPatches.value then + return + def patch2(denot: ClassDenotation, patchCls: Symbol): Unit = val scope = denot.info.decls.openForMutations diff --git a/tests/neg/no-patches.check b/tests/neg/no-patches.check new file mode 100644 index 000000000000..69428b83905d --- /dev/null +++ b/tests/neg/no-patches.check @@ -0,0 +1,12 @@ +-- [E008] Not Found Error: tests/neg/no-patches.scala:3:23 ------------------------------------------------------------- +3 |val _ = scala.language.`3.4` // error: we do not patch `scala.language` + | ^^^^^^^^^^^^^^^^^^^^ + | value 3.4 is not a member of object language +-- [E008] Not Found Error: tests/neg/no-patches.scala:4:36 ------------------------------------------------------------- +4 |val _ = scala.language.experimental.captureChecking // error: we do not patch `scala.language.experimental` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | value captureChecking is not a member of object language.experimental +-- [E008] Not Found Error: tests/neg/no-patches.scala:5:15 ------------------------------------------------------------- +5 |val _ = Predef.summon[DummyImplicit] // error: we do not patch `scala.Predef` + | ^^^^^^^^^^^^^ + | value summon is not a member of object Predef diff --git a/tests/neg/no-patches.scala b/tests/neg/no-patches.scala new file mode 100644 index 000000000000..9e36d0a84d88 --- /dev/null +++ b/tests/neg/no-patches.scala @@ -0,0 +1,5 @@ +//> using options -Yno-stdlib-patches + +val _ = scala.language.`3.4` // error: we do not patch `scala.language` +val _ = scala.language.experimental.captureChecking // error: we do not patch `scala.language.experimental` +val _ = Predef.summon[DummyImplicit] // error: we do not patch `scala.Predef`