Skip to content
Merged
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ private sealed trait YSettings:
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism. (This flag has no effect)", deprecation = Deprecation.removed())
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
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.")
val YnullifyTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Ynullify-tasty", "Apply nullification to Scala code compiled without -Yexplicit-nulls, when reading from tasty.")
val YsafeInitGlobal: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init-global", "Check safe initialization of global objects.")
val YrequireTargetName: Setting[Boolean] = BooleanSetting(ForkSetting, "Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation.")
val YrecheckTest: Setting[Boolean] = BooleanSetting(ForkSetting, "Yrecheck-test", "Run basic rechecking (internal test only).")
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ object Contexts {
/** Is the flexible types option set? */
def flexibleTypes: Boolean = base.settings.YexplicitNulls.value && !base.settings.YnoFlexibleTypes.value

def nullifyTasty: Boolean = base.settings.YexplicitNulls.value && base.settings.YnullifyTasty.value

/** Is the best-effort option set? */
def isBestEffort: Boolean = base.settings.YbestEffort.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ object ImplicitNullInterop:
else tp match
case tp: TypeRef
if !ctx.flexibleTypes && tp.isRef(defn.RepeatedParamClass) => false
case tp: TypeRef if defn.isTupleClass(tp.symbol) => false
case _ => true

override def apply(tp: Type): Type = tp match
Expand Down Expand Up @@ -193,7 +194,6 @@ object ImplicitNullInterop:
val savedSkipCurrentLevel = skipCurrentLevel
val savedSkipResultType = skipResultType

skipCurrentLevel = true
val parent2 = this(tp.parent)

skipCurrentLevel = false
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ class TreeUnpickler(reader: TastyReader,

def ta = ctx.typeAssigner

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

val name = readName()
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class CompilationTests {
locally {
val unsafeFile = compileFile("tests/explicit-nulls/flexible-unpickle/neg/Unsafe_1.scala", explicitNullsOptions without "-Yexplicit-nulls")
val flexibleFile = compileFile("tests/explicit-nulls/flexible-unpickle/neg/Flexible_2.scala",
explicitNullsOptions.withClasspath(defaultOutputDir + testGroup + "/Unsafe_1/neg/Unsafe_1"))
explicitNullsOptions.and("-Ynullify-tasty").withClasspath(defaultOutputDir + testGroup + "/Unsafe_1/neg/Unsafe_1"))

flexibleFile.keepOutput.checkExpectedErrors()

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

tests.foreach(_.delete())
Expand Down
Loading