Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 57235ef

Browse files
committed
Add -Ynullify-tasty setting and only nullify compiled Scala if the flag is set
1 parent 78495ea commit 57235ef

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

‎compiler/src/dotty/tools/dotc/config/ScalaSettings.scala‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ private sealed trait YSettings:
455455
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism. (This flag has no effect)", deprecation = Deprecation.removed())
456456
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
457457
val YnoFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-flexible-types", "Disable turning nullable Java return types and parameter types into flexible types, which behave like abstract types with a nullable lower bound and non-nullable upper bound.")
458+
val YnullifyTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Ynullify-tasty", "Apply nullification to Scala code compiled without -Yexplicit-nulls, when reading from tasty.")
458459
val YsafeInitGlobal: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init-global", "Check safe initialization of global objects.")
459460
val YrequireTargetName: Setting[Boolean] = BooleanSetting(ForkSetting, "Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation.")
460461
val YrecheckTest: Setting[Boolean] = BooleanSetting(ForkSetting, "Yrecheck-test", "Run basic rechecking (internal test only).")

‎compiler/src/dotty/tools/dotc/core/Contexts.scala‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ object Contexts {
480480
/** Is the flexible types option set? */
481481
def flexibleTypes: Boolean = base.settings.YexplicitNulls.value && !base.settings.YnoFlexibleTypes.value
482482

483+
def nullifyTasty: Boolean = base.settings.YexplicitNulls.value && base.settings.YnullifyTasty.value
484+
483485
/** Is the best-effort option set? */
484486
def isBestEffort: Boolean = base.settings.YbestEffort.value
485487

‎compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,10 @@ class TreeUnpickler(reader: TastyReader,
921921

922922
def ta = ctx.typeAssigner
923923

924-
// If explicit nulls is enabled, and the source file did not have explicit
924+
// If explicit nulls and `YnullifyTasty` is enabled, and the source file did not have explicit
925925
// nulls enabled, nullify the member to allow for compatibility.
926926
def nullify(sym: Symbol) =
927-
if (ctx.explicitNulls && ctx.flexibleTypes && !explicitNulls) then
927+
if (ctx.nullifyTasty && !explicitNulls) then
928928
sym.info = ImplicitNullInterop.nullifyMember(sym, sym.info, sym.is(Enum))
929929

930930
val name = readName()

‎compiler/test/dotty/tools/dotc/CompilationTests.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class CompilationTests {
217217
locally {
218218
val unsafeFile = compileFile("tests/explicit-nulls/flexible-unpickle/neg/Unsafe_1.scala", explicitNullsOptions without "-Yexplicit-nulls")
219219
val flexibleFile = compileFile("tests/explicit-nulls/flexible-unpickle/neg/Flexible_2.scala",
220-
explicitNullsOptions.withClasspath(defaultOutputDir + testGroup + "/Unsafe_1/neg/Unsafe_1"))
220+
explicitNullsOptions.and("-Ynullify-tasty").withClasspath(defaultOutputDir + testGroup + "/Unsafe_1/neg/Unsafe_1"))
221221

222222
flexibleFile.keepOutput.checkExpectedErrors()
223223

@@ -237,8 +237,8 @@ class CompilationTests {
237237
locally {
238238
val tests = List(
239239
compileFile("tests/explicit-nulls/flexible-unpickle/pos/Unsafe_1.scala", explicitNullsOptions without "-Yexplicit-nulls"),
240-
compileFile("tests/explicit-nulls/flexible-unpickle/pos/Flexible_2.scala", explicitNullsOptions.withClasspath(
241-
defaultOutputDir + testGroup + "/Unsafe_1/pos/Unsafe_1")),
240+
compileFile("tests/explicit-nulls/flexible-unpickle/pos/Flexible_2.scala",
241+
explicitNullsOptions.and("-Ynullify-tasty").withClasspath(defaultOutputDir + testGroup + "/Unsafe_1/pos/Unsafe_1")),
242242
).map(_.keepOutput.checkCompile())
243243

244244
tests.foreach(_.delete())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /