@@ -35,7 +35,7 @@ import dotty.tools.dotc.core.Decorators.i
35
35
* to handle the full spectrum of Scala types. Additionally, some kinds of symbols like constructors and
36
36
* enum instances get special treatment.
37
37
*/
38
- object ImplicitNullInterop {
38
+ object JavaNullInterop {
39
39
40
40
/** Transforms the type `tp` of Java member `sym` to be explicitly nullable.
41
41
* `tp` is needed because the type inside `sym` might not be set when this method is called.
@@ -55,11 +55,11 @@ object ImplicitNullInterop {
55
55
*/
56
56
def nullifyMember (sym : Symbol , tp : Type , isEnumValueDef : Boolean )(using Context ): Type = trace(i " nullifyMember ${sym}, ${tp}" ){
57
57
assert(ctx.explicitNulls)
58
+ assert(sym.is(JavaDefined ), " can only nullify java-defined members" )
58
59
59
60
// Some special cases when nullifying the type
60
- if isEnumValueDef || sym.name == nme.TYPE_ // Don't nullify the `TYPE` field in every class and Java enum instances
61
- || sym.is(Flags .ModuleVal ) // Don't nullify Modules
62
- then
61
+ if isEnumValueDef || sym.name == nme.TYPE_ then
62
+ // Don't nullify the `TYPE` field in every class and Java enum instances
63
63
tp
64
64
else if sym.name == nme.toString_ || sym.isConstructor || hasNotNullAnnot(sym) then
65
65
// Don't nullify the return type of the `toString` method.
@@ -80,14 +80,14 @@ object ImplicitNullInterop {
80
80
* but the result type is not nullable.
81
81
*/
82
82
private def nullifyExceptReturnType (tp : Type )(using Context ): Type =
83
- new ImplicitNullMap (outermostLevelAlreadyNullable = true )(tp)
83
+ new JavaNullMap (outermostLevelAlreadyNullable = true )(tp)
84
84
85
- /** Nullifies a type by adding `| Null` in the relevant places. */
85
+ /** Nullifies a Java type by adding `| Null` in the relevant places. */
86
86
private def nullifyType (tp : Type )(using Context ): Type =
87
- new ImplicitNullMap (outermostLevelAlreadyNullable = false )(tp)
87
+ new JavaNullMap (outermostLevelAlreadyNullable = false )(tp)
88
88
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.
89
+ /** A type map that implements the nullification function on types. Given a Java-sourced type, this adds `| Null`
90
+ * in the right places to make the nulls explicit in Scala .
91
91
*
92
92
* @param outermostLevelAlreadyNullable whether this type is already nullable at the outermost level.
93
93
* For example, `Array[String] | Null` is already nullable at the
@@ -97,7 +97,7 @@ object ImplicitNullInterop {
97
97
* This is useful for e.g. constructors, and also so that `A & B` is nullified
98
98
* to `(A & B) | Null`, instead of `(A | Null & B | Null) | Null`.
99
99
*/
100
- private class ImplicitNullMap (var outermostLevelAlreadyNullable : Boolean )(using Context ) extends TypeMap {
100
+ private class JavaNullMap (var outermostLevelAlreadyNullable : Boolean )(using Context ) extends TypeMap {
101
101
def nullify (tp : Type ): Type = if ctx.flexibleTypes then FlexibleType (tp) else OrNull (tp)
102
102
103
103
/** Should we nullify `tp` at the outermost level? */
0 commit comments