Commit b7d8ed87
b7d8ed87b1a8Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(analyze): RBS-arbitration accepts literal nil for declared T? return
rbs_inferred_incompatible? flagged a literal nil return as
conflicting with a declared T? (i.e. T | nil) return type.
But nil is a valid arm of that union — the conflict report was
rejecting MRI-valid code.
Surfaced in action_dispatch/flash via Rails-stack tests: methods
like Flash#[] declared String? with a nil early return
errored at analyze time. Same shape via every framework test
requiring action_dispatch.
Accept the nil arm: when rbs_t is a nullable T? and the literal return infers as nil, the union is satisfied.
Closes #638.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- b7d8ed87b1a8
- Parent
- d23bc1af84bd
spinel_analyze.rbmodifiedView file
@@ -20390,6 +20390,12 @@
2039020390
if base_type(rbs_t) == base_type(inf_t)2039120391
return false2039220392
end20393+
# Issue #638: a declared nullable return (`String?` = `String |20394+
# nil`) is satisfied by a literal `nil` return. Accept the nil20395+
# arm rather than flagging conflict.20396+
if is_nullable_type(rbs_t) == 1 && inf_t == "nil"20397+
return false20398+
end2039320399
# Container variant refinements where one is the other's poly form.2039420400
if (rbs_t == "int_array" && inf_t == "poly_array") ||2039520401
(rbs_t == "poly_array" && inf_t == "int_array")