@@ -102,18 +102,19 @@ object ImplicitNullInterop {
102
102
103
103
/** Should we nullify `tp` at the outermost level? */
104
104
def needsNull (tp : Type ): Boolean =
105
- if outermostLevelAlreadyNullable then false
105
+ if outermostLevelAlreadyNullable || ! tp.hasSimpleKind then false
106
106
else tp match
107
- case tp : TypeRef if ! tp.hasSimpleKind
107
+ case tp : TypeRef =>
108
108
// We don't modify value types because they're non-nullable even in Java.
109
- || tp.symbol.isValueClass
109
+ ! (tp.symbol.isValueClass
110
+ // We don't modify some special types.
110
111
|| tp.isRef(defn.NullClass )
111
112
|| tp.isRef(defn.NothingClass )
112
- // We don't modify unit types.
113
113
|| tp.isRef(defn.UnitClass )
114
- // We don't modify `Any` because it's already nullable.
115
- || tp.isRef(defn.AnyClass ) => false
116
- case tp : TypeParamRef if ! tp.hasSimpleKind => false
114
+ || tp.isRef(defn.SingletonClass )
115
+ || tp.isRef(defn.AnyValClass )
116
+ || tp.isRef(defn.AnyKindClass )
117
+ || tp.isRef(defn.AnyClass ))
117
118
case _ => true
118
119
119
120
// We don't nullify Java varargs at the top level.
@@ -156,17 +157,19 @@ object ImplicitNullInterop {
156
157
outermostLevelAlreadyNullable = true
157
158
nullify(derivedAndType(tp, this (tp.tp1), this (tp.tp2)))
158
159
case tp : TypeParamRef if needsNull(tp) => nullify(tp)
159
- // In all other cases, return the type unchanged.
160
- // In particular, if the type is a ConstantType, then we don't nullify it because it is the
161
- // type of a final non-nullable field.
162
160
case tp : ExprType => mapOver(tp)
163
- case tp : AnnotatedType => mapOver(tp)
161
+ case tp : AnnotatedType =>
162
+ // We don't nullify the annotation part.
163
+ derivedAnnotatedType(tp, this (tp.underlying), tp.annot)
164
164
case tp : OrType =>
165
165
outermostLevelAlreadyNullable = true
166
166
nullify(derivedOrType(tp, this (tp.tp1), this (tp.tp2)))
167
167
case tp : RefinedType =>
168
168
outermostLevelAlreadyNullable = true
169
169
nullify(mapOver(tp))
170
+ // In all other cases, return the type unchanged.
171
+ // In particular, if the type is a ConstantType, then we don't nullify it because it is the
172
+ // type of a final non-nullable field.
170
173
case _ => tp
171
174
}
172
175
}
0 commit comments