Commit 30461528
30461528d72cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): empty {} literal coerces to expected hash variant
compile_expr_for_expected_type fell through to compile_expr for
empty hash literals, which always emit `sp_StrIntHash_new()`.
When the expected slot was sp_StrPolyHash * / sp_SymStrHash * /
etc., the assignment tripped -Wincompatible-pointer-types and the
generated C carried a quiet type mismatch (the runtime layout
diverges between hash variants).
Call empty_hash_coerce before compile_expr so the empty literal emits the variant's own _new() helper matching the destination.
Surfaces as the most common warning shape in #685's roundhouse
real-blog emit: every sp_StrPolyHash * _t = sp_StrIntHash_new()
warning vanishes after this. Remaining shapes in that issue are
unrelated (poly-recv attr-read flowing into typed constructor
params, inherited cls-method RBS sig propagation).
Tests: default 458/0/0, promote 458/0/0, optcarrot checksum 59662.
Refs #685
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 30461528d72c
- Parent
- 6c2466b5ec9b
spinel_codegen.rbmodifiedView file
return val end end # Empty `{}` literal against a typed hash slot: emit the variant's # own _new() rather than the default sp_StrIntHash_new() so the # value's static type matches the destination (avoids -Wincompatible- # pointer-types when the expected slot is sp_StrPolyHash * / # sp_SymStrHash * / etc.). eh_val = empty_hash_coerce(nid, expected_base) if eh_val != "" return eh_val end # `[nil] * N` / `[0] * N` against a pointer-array LHS: build a # fresh ptr_array pre-filled with N NULLs so subsequent # `arr[i] = obj` writes via sp_PtrArray_set land in valid slots.