@@ -63,26 +63,29 @@ object JavaNullInterop {
63
63
// Don't nullify the return type of the `toString` method.
64
64
// Don't nullify the return type of constructors.
65
65
// Don't nullify the return type of methods with a not-null annotation.
66
- nullifyExceptReturnType(tp, sym.owner.isClass )
66
+ nullifyExceptReturnType(tp)
67
67
else
68
68
// Otherwise, nullify everything
69
- nullifyType(tp, sym.owner.isClass )
69
+ nullifyType(tp)
70
70
}
71
71
72
72
private def hasNotNullAnnot (sym : Symbol )(using Context ): Boolean =
73
73
ctx.definitions.NotNullAnnots .exists(nna => sym.unforcedAnnotation(nna).isDefined)
74
74
75
+ private def javaNullMap (outermostLevelAlreadyNullable : Boolean )(using Context ): TypeMap =
76
+ if ctx.flexibleTypes then new JavaFlexibleMap (outermostLevelAlreadyNullable) else new JavaNullMap (outermostLevelAlreadyNullable)
77
+
75
78
/** If tp is a MethodType, the parameters and the inside of return type are nullified,
76
79
* but the result return type is not nullable.
77
80
* If tp is a type of a field, the inside of the type is nullified,
78
81
* but the result type is not nullable.
79
82
*/
80
- private def nullifyExceptReturnType (tp : Type , ownerIsClass : Boolean )(using Context ): Type =
81
- if ctx.flexibleTypes /* && ownerIsClass */ then new JavaFlexibleMap ( true )(tp) else new JavaNullMap ( true )(tp) // FLEX PARAMS
83
+ private def nullifyExceptReturnType (tp : Type )(using Context ): Type =
84
+ javaNullMap(outermostLevelAlreadyNullable = true )(tp)
82
85
83
86
/** Nullifies a Java type by adding `| Null` in the relevant places. */
84
- private def nullifyType (tp : Type , ownerIsClass : Boolean )(using Context ): Type =
85
- if ctx.flexibleTypes /* && ownerIsClass */ then new JavaFlexibleMap ( false )(tp) else new JavaNullMap ( false )(tp) // FLEX PARAMS
87
+ private def nullifyType (tp : Type )(using Context ): Type =
88
+ javaNullMap(outermostLevelAlreadyNullable = false )(tp)
86
89
87
90
/** A type map that implements the nullification function on types. Given a Java-sourced type, this adds `| Null`
88
91
* in the right places to make the nulls explicit in Scala.
0 commit comments