Commit 5465db8a
5465db8ad48dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): int? truthy check uses SP_INT_NIL sentinel, not NULL
compile_cond_expr and truthy_c_expr both routed nullable types
through expr != NULL. For int? (the SP_INT_NIL scalar-sentinel
nullable), comparing the mrb_int slot to NULL is semantically wrong
(SP_INT_NIL is INT64_MIN, not 0) and triggers -Wint-conversion
"comparison between pointer and integer".
Route int? through the existing scalar-nullable arm:
!sp_int_is_nil(expr). Other nullable types (pointer-shaped) stay
on the != NULL path.
Surfaces in #685's roundhouse emit at lv_form_class || "button_to"
where lv_form_class is int? from a hash lookup -- the ||
lowered to a ternary whose cond used _t333 != NULL.
Tests: default 460/0/0, promote 460/0/0, optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 5465db8ad48d
- Parent
- 66e7a44e4dc8
spinel_codegen.rbmodifiedView file
if t == "void" || t == "nil" return "FALSE" end # `int?` uses the SP_INT_NIL sentinel, not NULL — comparing the # mrb_int slot to NULL warns -Wint-conversion and is semantically # wrong (SP_INT_NIL is INT64_MIN, not 0). Route through the # scalar-nullable arm. if is_scalar_nullable_type(t) == 1 return "(!sp_int_is_nil(" + expr + "))" end if is_nullable_type(t) == 1 return "(" + expr + " != NULL)" end if t == "nil" return "FALSE" end # See compile_cond_expr -- `int?` uses SP_INT_NIL, not NULL. if is_scalar_nullable_type(t) == 1 return "(!sp_int_is_nil(" + expr + "))" end if is_nullable_type(t) == 1 || type_is_pointer(t) == 1 return "(" + expr + " != NULL)" end