Commit 76e6991b

76e6991b0289Merged

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

Description

fix: Hash#dup coverage + include-chain const lookup + array equality + regex flag-group parse

Four batched fixes addressing recent Sam Ruby / Adam Doppelt issues.

#592 -- Hash#dup was missing from the str_str_hash and int_str_hash codegen dispatch arms even though the runtime helpers (sp_StrStrHash_dup, sp_IntStrHash_dup) were defined. h = {"a" => "1"}; m = h.dup emitted cannot resolve call to 'dup' on str_str_hash (emitting 0) and subsequent .length / []= on the int-typed 0 segfaulted. Adds the missing if mname == "dup" || mname == "clone" arms to each variant.

#591 -- Bare CONST from an instance method body attached to a class via include M left the const-resolution chain at the host class and missed M's namespace. Sibling to #573's method-attachment fix (b034816 reconcile_class_includes): the methods were copied to the host class but resolve_const_read_name's scope walk didn't consult @cls_includes. Adds the include-chain fallback to both the analyzer's and codegen's resolvers.

#600 puzzle 1 -- [0, 0, 0] != %i[a a a] returned false. sym_array shares the sp_IntArray layout and sp_IntArray_eq compares raw bytes; with SPS_a == 0, both arrays encoded to [0,0,0] and the eq returned true. Fix: when the recv AND first arg are both ArrayNode literals and the static types differ (int_array vs sym_array), short-circuit to FALSE. The <<-widened "int_array carrying syms at runtime" shape from issue #555 keeps both sides typed int_array (the analyzer leaves the static type alone), so the guard doesn't engage and IntArray_eq continues to drive the comparison.

#600 puzzle 3 -- /(?x:foo)/.to_s hung at runtime during the static-regex compilation. re_compile.c's (? parser handled :, =, !, <...>, <=, <! directives but fell through on ?<flag-char> (x / i / m / s / u / a). With no advance, compile_seq's outer loop spun on the unconsumed ?. Fix: when the (? lookahead matches a recognized inline-flag char, consume to the trailing : (non-capturing body) or ) (whole-group flag application -- spinel doesn't honor scoped flag SEMANTICS yet, just consumes the directive). Unrecognized (?<X> raises unrecognized (? construct compile_error instead of hanging. /x's whitespace-stripping is NOT applied inside the sub-pattern (top-level strip only); patterns with literal-character bodies (like the puzzle's (?x:foo)) match unchanged. The puzzle's .to_s still returns "0" since spinel doesn't implement Regexp#to_s, but it no longer hangs.

make test: 574/574 pass. make optcarrot: checksum 59662. Stage-2 bootstrap fixpoint clean.

Closes #592 Closes #591 Refs #600 (puzzles 1 + 3 fixed; puzzle 2 Hash.new(default_value) requires runtime-side default tracking and stays open for a future structural change.)

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

Details

Commit
76e6991b0289
Parent
a34770e897b1

lib/regexp/re_compile.cmodifiedView file

@@ -443,6 +443,42 @@
443443 cap_name_len = (uint16_t)(c->p - cap_name);
444444 next_char(c); /* skip > */
445445 }
446+ else {
447+ /* Inline-flag group `(?xim-xim:...)` or whole-group flag
448+ `(?xim)`. Skip the flag chars (and optional `-flags`),
449+ then either `:` (non-capturing body) or `)` (apply to
450+ outer group). Spinel's compiler doesn't honour the
451+ flag SEMANTICS yet -- /x in particular would need to
452+ strip whitespace inside this sub-pattern only -- but
453+ the parse now consumes the directive so compile_seq
454+ advances. Without this, `(?x:foo)` left c->p stuck on
455+ `?` and compile_seq's outer loop spun forever. */
456+ int c1 = c->p[1];
457+ int recognized_flag = (c1 == 'x' || c1 == 'i' || c1 == 'm' || c1 == 's' || c1 == 'u' || c1 == 'a');
458+ if (recognized_flag) {
459+ next_char(c); /* skip ? */
460+ while (peek(c) != ':' && peek(c) != ')' && peek(c) >= 0) next_char(c);
461+ if (peek(c) == ':') {
462+ next_char(c); /* skip : */
463+ capturing = FALSE;
464+ }
465+ else if (peek(c) == ')') {
466+ /* `(?xim)` with no body — apply to the enclosing
467+ group; spinel doesn't track per-scope flags, so
468+ just consume the close paren and emit nothing.
469+ The atom loop will see the next token. */
470+ next_char(c);
471+ break;
472+ }
473+ }
474+ else {
475+ /* Unrecognized `(?<X>...` directive. Compile-error
476+ instead of looping: better surface than the prior
477+ infinite-loop wedge. */
478+ compile_error(c, "unrecognized (? construct");
479+ break;
480+ }
481+ }
446482 }
447483
448484 uint16_t group = 0;