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

@@ -12118,6 +12118,13 @@
1211812118 if t == "void" || t == "nil"
1211912119 return "FALSE"
1212012120 end
12121+ # `int?` uses the SP_INT_NIL sentinel, not NULL — comparing the
12122+ # mrb_int slot to NULL warns -Wint-conversion and is semantically
12123+ # wrong (SP_INT_NIL is INT64_MIN, not 0). Route through the
12124+ # scalar-nullable arm.
12125+ if is_scalar_nullable_type(t) == 1
12126+ return "(!sp_int_is_nil(" + expr + "))"
12127+ end
1212112128 if is_nullable_type(t) == 1
1212212129 return "(" + expr + " != NULL)"
1212312130 end
@@ -12152,6 +12159,10 @@
1215212159 if t == "nil"
1215312160 return "FALSE"
1215412161 end
12162+ # See compile_cond_expr -- `int?` uses SP_INT_NIL, not NULL.
12163+ if is_scalar_nullable_type(t) == 1
12164+ return "(!sp_int_is_nil(" + expr + "))"
12165+ end
1215512166 if is_nullable_type(t) == 1 || type_is_pointer(t) == 1
1215612167 return "(" + expr + " != NULL)"
1215712168 end