Commit 39d081dc

39d081dc7046Merged

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

Description

Fix hash_dig multi-key type inference and array_combination_block boxing

  • hash_dig: for PolyPolyHash, infer each sub-key type from the actual argument rather than from the parent key type, fixing CC errors on string-keyed multi-step dig calls
  • array_combination_block: box combination result as sp_RbVal when the block param is typed TY_POLY, avoiding incompatible-type CC errors

Also add Fiber[:k]/Fiber.current[:k] storage get/set support (sp_Fiber_storage_get/set) and ENV[]/ENV.fetch codegen, enabling fiber_storage_* and env_string_inference tests to pass.

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

Details

Commit
39d081dc7046
Parent
d99fb4909e70

src/analyze.cmodifiedView file

@@ -622,6 +622,53 @@
622622 }
623623 }
624624
625+ /* Fiber storage: Fiber[:k] and Fiber.current[:k] -> poly */
626+ if (recv >= 0 && !strcmp(name, "[]") && argc == 1) {
627+ const char *rty = nt_type(nt, recv);
628+ if (rty && !strcmp(rty, "ConstantReadNode")) {
629+ const char *rn = nt_str(nt, recv, "name");
630+ if (rn && !strcmp(rn, "Fiber")) return TY_POLY;
631+ }
632+ if (rty && !strcmp(rty, "CallNode")) {
633+ const char *rn = nt_str(nt, recv, "name");
634+ int rr = nt_ref(nt, recv, "receiver");
635+ if (rn && !strcmp(rn, "current") && rr >= 0) {
636+ const char *rrty = nt_type(nt, rr);
637+ const char *rrn = nt_str(nt, rr, "name");
638+ if (rrty && !strcmp(rrty, "ConstantReadNode") && rrn && !strcmp(rrn, "Fiber"))
639+ return TY_POLY;
640+ }
641+ }
642+ }
643+ /* Fiber[:k] = v -> returns v's type */
644+ if (recv >= 0 && !strcmp(name, "[]=") && argc == 2) {
645+ const char *rty = nt_type(nt, recv);
646+ int is_fiber = 0;
647+ if (rty && !strcmp(rty, "ConstantReadNode")) {
648+ const char *rn = nt_str(nt, recv, "name");
649+ if (rn && !strcmp(rn, "Fiber")) is_fiber = 1;
650+ }
651+ else if (rty && !strcmp(rty, "CallNode")) {
652+ const char *rn = nt_str(nt, recv, "name");
653+ int rr = nt_ref(nt, recv, "receiver");
654+ if (rn && !strcmp(rn, "current") && rr >= 0) {
655+ const char *rrty = nt_type(nt, rr);
656+ const char *rrn = nt_str(nt, rr, "name");
657+ if (rrty && !strcmp(rrty, "ConstantReadNode") && rrn && !strcmp(rrn, "Fiber"))
658+ is_fiber = 1;
659+ }
660+ }
661+ if (is_fiber) return infer_type(c, argv[1]);
662+ }
663+ /* ENV[key] -> string or nil (use TY_STRING; null means nil) */
664+ if (recv >= 0 && argc >= 1 && (!strcmp(name, "[]") || !strcmp(name, "fetch"))) {
665+ const char *rty = nt_type(nt, recv);
666+ if (rty && !strcmp(rty, "ConstantReadNode")) {
667+ const char *rn = nt_str(nt, recv, "name");
668+ if (rn && !strcmp(rn, "ENV")) return TY_STRING;
669+ }
670+ }
671+
625672 /* array receiver methods */
626673 if (recv >= 0 && ty_is_array(rt)) {
627674 int block = nt_ref(nt, id, "block");