Commit baf0def3
baf0def3c351Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
case/when: a different-family when value never matches
case <string> when :sym (and the symmetric symbol-vs-string) emit a
literal false for the cross-type arm instead of a strcmp/== with
mismatched C types, falling through to else as CRuby does.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- baf0def3c351
- Parent
- 510272696d02
src/codegen.cmodifiedView file
@@ -4060,6 +4060,10 @@
40604060
buf_printf(b, "({ sp_Range _t%d = ", tr); emit_expr(c, conds[j], b);40614061
buf_printf(b, "; sp_range_include(&_t%d, _t%d); })", tr, t);40624062
}4063+
else if (eq_family(pt) && eq_family(comp_ntype(c, conds[j])) && eq_family(pt) != eq_family(comp_ntype(c, conds[j]))) {4064+
/* a when value of a different comparable family never matches */4065+
buf_puts(b, "0");4066+
}40634067
else if (pt == TY_STRING) {40644068
buf_printf(b, "sp_str_eq(_t%d, ", t); emit_expr(c, conds[j], b); buf_puts(b, ")");40654069
}@@ -4134,6 +4138,10 @@
41344138
buf_printf(b, "({ sp_Range _t%d = ", tr); emit_expr(c, conds[j], b);41354139
buf_printf(b, "; sp_range_include(&_t%d, _t%d); })", tr, t);41364140
}4141+
else if (eq_family(pt) && eq_family(comp_ntype(c, conds[j])) && eq_family(pt) != eq_family(comp_ntype(c, conds[j]))) {4142+
/* a when value of a different comparable family never matches */4143+
buf_puts(b, "0");4144+
}41374145
else if (pt == TY_STRING) { buf_printf(b, "sp_str_eq(_t%d, ", t); emit_expr(c, conds[j], b); buf_puts(b, ")"); }41384146
else { buf_printf(b, "(_t%d == ", t); emit_expr(c, conds[j], b); buf_puts(b, ")"); }41394147
}