Commit dcb0590c

dcb0590ca076Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Fix minmax/sort block comparator body type inference

Block params for comparator blocks (min/max/minmax/sort) get widened to TY_POLY when multiple blocks share the same scope with the same param names. This caused several failures:

  • emit_minmax_cmp_expr returned 0 (fell to unsupported) because the body <=> node cached as TY_UNKNOWN (fixpoint skips body analysis)
  • Even when the check was bypassed, lv_a/lv_b are sp_RbVal (TY_POLY declaration), so direct scalar assignment failed with -Werror

Fixes:

  • analyze.c: <=> always returns TY_INT (was guarded by type check that excluded TY_POLY operands; second branch unreachable since is_cmp_op excludes <=>)
  • codegen.c emit_minmax_cmp_expr / emit_sort_cmp_expr / emit_minmax_by_expr: use infer_type (live) instead of comp_ntype (stale cache) for body type check and for comparator receiver in the <=> handler
  • emit_minmax_cmp_expr: emit C shadow declarations { et lv_p0=_t_te; ... } so the body uses et-typed variables, with scope types temporarily pinned to et and cache refreshed via infer_type before body emission
  • Also fixes block-param save/restore to use emit_ctype rather than hard-coding sp_RbVal, fixing 6 regressions in typed-array each loops

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
dcb0590ca076
Parent
ef9704349dff

src/analyze.cmodifiedView file

@@ -896,13 +896,8 @@
896896 return (rt == TY_FLOAT || a0 == TY_FLOAT) ? TY_FLOAT : TY_INT;
897897 return TY_UNKNOWN;
898898 }
899- if (recv >= 0 && argc == 1 && !strcmp(name, "<=>") &&
900- ((ty_is_numeric(rt) && ty_is_numeric(a0)) || (rt == TY_STRING && a0 == TY_STRING)))
901- return TY_INT;
902- if (recv >= 0 && argc == 1 && is_cmp_op(name)) {
903- if (!strcmp(name, "<=>")) return TY_INT;
904- return TY_BOOL;
905- }
899+ if (recv >= 0 && argc == 1 && !strcmp(name, "<=>")) return TY_INT;
900+ if (recv >= 0 && argc == 1 && is_cmp_op(name)) return TY_BOOL;
906901 if (argc == 1 && is_eq_op(name)) return TY_BOOL;
907902
908903 /* integer bitwise operators */