|
|
@ -95,13 +95,20 @@ module ReportableViolation = struct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
let check type_role ~base ~overridden =
|
|
|
|
let check type_role ~base ~overridden =
|
|
|
|
let subtype, supertype =
|
|
|
|
if Nullability.equal Nullability.ThirdPartyNonnull base then
|
|
|
|
match type_role with
|
|
|
|
(* In context of inheritance check, third party declarations in base are treated optimistically.
|
|
|
|
| Ret ->
|
|
|
|
Meaning return values are assumed [@Nullable] and params are assumed [@NonNull].
|
|
|
|
(* covariance for ret *)
|
|
|
|
This is done for compatibility reasons so existing [@Nullsafe] classes are preserved Nullsafe.
|
|
|
|
(overridden, base)
|
|
|
|
*)
|
|
|
|
| Param ->
|
|
|
|
Ok ()
|
|
|
|
(* contravariance for param *)
|
|
|
|
else
|
|
|
|
(base, overridden)
|
|
|
|
let subtype, supertype =
|
|
|
|
in
|
|
|
|
match type_role with
|
|
|
|
Result.ok_if_true (Nullability.is_subtype ~subtype ~supertype) ~error:{base; overridden}
|
|
|
|
| Ret ->
|
|
|
|
|
|
|
|
(* covariance for ret *)
|
|
|
|
|
|
|
|
(overridden, base)
|
|
|
|
|
|
|
|
| Param ->
|
|
|
|
|
|
|
|
(* contravariance for param *)
|
|
|
|
|
|
|
|
(base, overridden)
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
Result.ok_if_true (Nullability.is_subtype ~subtype ~supertype) ~error:{base; overridden}
|
|
|
|