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

@@ -5992,6 +5992,15 @@
59925992 return val
59935993 end
59945994 end
5995+ # Empty `{}` literal against a typed hash slot: emit the variant's
5996+ # own _new() rather than the default sp_StrIntHash_new() so the
5997+ # value's static type matches the destination (avoids -Wincompatible-
5998+ # pointer-types when the expected slot is sp_StrPolyHash * /
5999+ # sp_SymStrHash * / etc.).
6000+ eh_val = empty_hash_coerce(nid, expected_base)
6001+ if eh_val != ""
6002+ return eh_val
6003+ end
59956004 # `[nil] * N` / `[0] * N` against a pointer-array LHS: build a
59966005 # fresh ptr_array pre-filled with N NULLs so subsequent
59976006 # `arr[i] = obj` writes via sp_PtrArray_set land in valid slots.