Skip to content

Commit 917e4e8

Browse files
olhotakmbovel
authored andcommitted
Revert "Refactor JavaNullInterop to reflect new usage"
This reverts commit 5a87908.
1 parent efd4a7d commit 917e4e8

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

compiler/src/dotty/tools/dotc/core/ImplicitNullInterop.scala renamed to compiler/src/dotty/tools/dotc/core/JavaNullInterop.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import dotty.tools.dotc.core.Decorators.i
3535
* to handle the full spectrum of Scala types. Additionally, some kinds of symbols like constructors and
3636
* enum instances get special treatment.
3737
*/
38-
object ImplicitNullInterop {
38+
object JavaNullInterop {
3939

4040
/** Transforms the type `tp` of Java member `sym` to be explicitly nullable.
4141
* `tp` is needed because the type inside `sym` might not be set when this method is called.
@@ -55,6 +55,7 @@ object ImplicitNullInterop {
5555
*/
5656
def nullifyMember(sym: Symbol, tp: Type, isEnumValueDef: Boolean)(using Context): Type = trace(i"nullifyMember ${sym}, ${tp}"){
5757
assert(ctx.explicitNulls)
58+
// assert(sym.is(JavaDefined), "can only nullify java-defined members")
5859

5960
// Some special cases when nullifying the type
6061
if isEnumValueDef || sym.name == nme.TYPE_ // Don't nullify the `TYPE` field in every class and Java enum instances
@@ -80,14 +81,14 @@ object ImplicitNullInterop {
8081
* but the result type is not nullable.
8182
*/
8283
private def nullifyExceptReturnType(tp: Type)(using Context): Type =
83-
new ImplicitNullMap(outermostLevelAlreadyNullable = true)(tp)
84+
new JavaNullMap(outermostLevelAlreadyNullable = true)(tp)
8485

85-
/** Nullifies a type by adding `| Null` in the relevant places. */
86+
/** Nullifies a Java type by adding `| Null` in the relevant places. */
8687
private def nullifyType(tp: Type)(using Context): Type =
87-
new ImplicitNullMap(outermostLevelAlreadyNullable = false)(tp)
88+
new JavaNullMap(outermostLevelAlreadyNullable = false)(tp)
8889

89-
/** A type map that implements the nullification function on types. Given a Java-sourced type or an
90-
* implicitly null type, this adds `| Null` in the right places to make the nulls explicit.
90+
/** A type map that implements the nullification function on types. Given a Java-sourced type, this adds `| Null`
91+
* in the right places to make the nulls explicit in Scala.
9192
*
9293
* @param outermostLevelAlreadyNullable whether this type is already nullable at the outermost level.
9394
* For example, `Array[String] | Null` is already nullable at the
@@ -97,7 +98,7 @@ object ImplicitNullInterop {
9798
* This is useful for e.g. constructors, and also so that `A & B` is nullified
9899
* to `(A & B) | Null`, instead of `(A | Null & B | Null) | Null`.
99100
*/
100-
private class ImplicitNullMap(var outermostLevelAlreadyNullable: Boolean)(using Context) extends TypeMap {
101+
private class JavaNullMap(var outermostLevelAlreadyNullable: Boolean)(using Context) extends TypeMap {
101102
def nullify(tp: Type): Type = if ctx.flexibleTypes then FlexibleType(tp) else OrNull(tp)
102103

103104
/** Should we nullify `tp` at the outermost level? */

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,6 @@ object Types extends TypeUtils {
34323432
// flexible type is always a subtype of the original type and the Object type.
34333433
// It is not necessary according to the use cases, so we choose to use a simpler
34343434
// rule.
3435-
assert(!tp.isInstanceOf[LazyType])
34363435
FlexibleType(OrNull(tp), tp)
34373436
}
34383437
}

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class ClassfileParser(
525525
denot.info = translateTempPoly(attrCompleter.complete(denot.info, isVarargs))
526526
if (isConstructor) normalizeConstructorInfo()
527527

528-
if (ctx.explicitNulls) denot.info = ImplicitNullInterop.nullifyMember(denot.symbol, denot.info, isEnum)
528+
if (ctx.explicitNulls) denot.info = JavaNullInterop.nullifyMember(denot.symbol, denot.info, isEnum)
529529

530530
// seal java enums
531531
if (isEnum) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ class TreeUnpickler(reader: TastyReader,
985985
// If explicit nulls is enabled, and the source file did not have explicit
986986
// nulls enabled, nullify the member to allow for compatibility.
987987
if (ctx.explicitNulls && !explicitNulls) then
988-
sym.info = ImplicitNullInterop.nullifyMember(sym, sym.info, sym.is(Enum))
988+
sym.info = JavaNullInterop.nullifyMember(sym, sym.info, sym.is(Enum))
989989

990990
goto(end)
991991
setSpan(start, tree)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ class Namer { typer: Typer =>
19021902

19031903
val mbrTpe = paramFn(checkSimpleKinded(typedAheadType(mdef.tpt, tptProto)).tpe)
19041904
if (ctx.explicitNulls && mdef.mods.is(JavaDefined))
1905-
ImplicitNullInterop.nullifyMember(sym, mbrTpe, mdef.mods.isAllOf(JavaEnumValue))
1905+
JavaNullInterop.nullifyMember(sym, mbrTpe, mdef.mods.isAllOf(JavaEnumValue))
19061906
else mbrTpe
19071907
}
19081908

0 commit comments

Comments
 (0)