Commit 7cc64b24

7cc64b24149aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

analyze: merge_refined_local_type accepts time -> float

elapsed = Time.now - start left lv_elapsed as sp_Time even though codegen emitted a stmt-expression of type mrb_float ((_a.tv_sec - _b.tv_sec) + ...), tripping a C type mismatch.

Root cause: scan_locals' pass 1 walks Time.now - start before start is declared via declare_var. infer_type(start) returns the int default; the - arm's time-branch then takes the "Time - Numeric -> Time" path. Pass 2 re-infers (start declared) as float per "Time - Time -> Float", but merge_refined_local_type had no time->float arm and returned "" (no change).

Add the time->float refinement.

Refs #901

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
7cc64b24149a
Parent
d3558d524e45

spinel_analyze.rbmodifiedView file

@@ -19941,6 +19941,13 @@
1994119941 return new_t
1994219942 end
1994319943 end
19944+ # Issue #901: Time - Time → float. Pass 1 sees the rhs LV as
19945+ # int (not yet declared) so the `-` arm returns "time"
19946+ # (Time - Numeric path). Pass 2 re-infers as "float" once the
19947+ # rhs LV is declared as time. Accept the refinement.
19948+ if cur_t == "time" && new_t == "float"
19949+ return new_t
19950+ end
1994419951 ""
1994519952 end
1994619953