Commit 6fe12da7
6fe12da7e47dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(codegen,analyze): String#!~ (regex no-match operator) (#732)
"x" !~ /pattern/ used to fall through to the unresolved-call
warning ("cannot resolve call to '!~' on string"). spinel handled
=~ but never wired up the negated form.
Fix:
- compile_call: new
!~arm mirroring=~'s pattern compilation (regex_pat_c_expr -> sp_re_match_poly), then checks the result's tag for SP_TAG_NIL (no-match -> true). When no pattern arg is given, returns true unconditionally to mirror "no possible match". - analyze.rb:
!~returns "bool" so callers get the right typing for if/puts/etc.
Test: test/not_match_op.rb covers match/no-match across literal
and \d+ patterns.
468 tests pass; optcarrot checksum 59662.
Closes #732
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 6fe12da7e47d
- Parent
- f99002b2b5c4
spinel_analyze.rbmodifiedView file
@@ -3515,6 +3515,10 @@
35153515
@needs_rb_value = 135163516
return "poly"35173517
end3518+
if mname == "!~"3519+
# Negation of `=~`: bool. Issue #732.3520+
return "bool"3521+
end35183522
if mname == "<<"35193523
if recv >= 035203524
if lt == "mutable_str"spinel_codegen.rbmodifiedView file
Loading diff…
test/not_match_op.rbaddedView file
Loading diff…
test/not_match_op.rb.expectedaddedView file
Loading diff…