Commit e7a21d11

e7a21d11862aMerged

Tomoyuki INOUE <[email protected]> · 6 months ago · 4 files · ~4 modified

Description

fix(analyze,codegen): Time#isdst / #dst? return bool, not int

Review (matz/spinel#565, gemini-code-assist medium): isdst / dst? were grouped with the integer accessors and inferred as "int", so p t.isdst / t.dst? printed 0/1 instead of CRuby's false/true. Split them into a dedicated bool inference arm; codegen emits the boolean expression (sp_time_isdst(...) != 0). sp_time_isdst's 0/1 return is unchanged, runtime untouched. test/time_accessors.rb now covers Time.at(0).utc.isdst / .dst? (TZ-independent, both false); .expected regenerated from CRuby 3.4.6, byte-identical. make / bootstrap (4 fixpoints) / make test 533 pass all green.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
e7a21d11862a
Parent
17a0a15dbe77

spinel_analyze.rbmodifiedView file

@@ -3716,11 +3716,18 @@
37163716 # receiver so user classes defining same-named methods still
37173717 # flow through normal resolution. Local Time.new is in scope;
37183718 # the fixed-offset 7-arg form is a separate Issue.
3719- if mname == "year" || mname == "mon" || mname == "month" || mname == "mday" || mname == "day" || mname == "hour" || mname == "min" || mname == "sec" || mname == "wday" || mname == "yday" || mname == "isdst" || mname == "dst?" || mname == "utc_offset" || mname == "gmt_offset" || mname == "gmtoff"
3719+ if mname == "year" || mname == "mon" || mname == "month" || mname == "mday" || mname == "day" || mname == "hour" || mname == "min" || mname == "sec" || mname == "wday" || mname == "yday" || mname == "utc_offset" || mname == "gmt_offset" || mname == "gmtoff"
37203720 if recv >= 0 && infer_type(recv) == "time"
37213721 return "int"
37223722 end
37233723 end
3724+ # isdst / dst? are predicates: CRuby returns true / false,
3725+ # not 0 / 1, so they infer as bool (not the int accessor group).
3726+ if mname == "isdst" || mname == "dst?"
3727+ if recv >= 0 && infer_type(recv) == "time"
3728+ return "bool"
3729+ end
3730+ end
37243731 if mname == "zone"
37253732 if recv >= 0 && infer_type(recv) == "time"
37263733 return "string"