Skip to content

fix(parser): def !~ operator method, and class << with an assignment target - #17

Merged
tannevaled merged 1 commit into
mainfrom
fix/def-nmatch-and-singleton-assign
Aug 15, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix/def-nmatch-and-singleton-assign

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

Two def/class forms MRI accepts were rejected by the parser:

  • def !~(other) — the not-match operator method. !~ lexes as one NMATCH token and is already a valid binary operator, but parseDefName listed MATCH (=~) and not NMATCH, so def !~ failed with "expected method name after def". != was also untested (though NEQ was already handled).
  • class << @x = Object.new — the singleton-class target may be a full assignment expression (assign, then open the result's singleton class), so it is now parsed with parseExprOrAssign rather than parseTernary, which stopped at the =.

Both are exercised by ruby/spec (Kernel#!~, Kernel#public_send), whose spec files failed to even load in the downstream go-embedded-ruby interpreter because of these parse errors.

Tests

  • TestOperatorMethodDef gains !~ and !=.
  • New TestSingletonClassAssignTarget (target is an IvarAssign).
  • go vet ./..., the full suite, and the 100% merged-coverage gate stay green; class << self / << obj / << obj.thing still parse.

🤖 Generated with Claude Code

…target

Two def/class forms MRI accepts were rejected:

  * def !~(other) — the not-match operator method. NMATCH lexes as one token
    and is a valid binary operator, but parseDefName listed MATCH (=~) and not
    NMATCH, so def !~ failed with "expected method name after def". != was
    also untested though NEQ was already handled.
  * class << @x = Object.new — the singleton-class target may be a full
    assignment expression (assign, then open the result's singleton), so it is
    parsed with parseExprOrAssign rather than parseTernary, which stopped at
    the '='.

Both are exercised by ruby/spec (Kernel#!~, Kernel#public_send). Tests added
to TestOperatorMethodDef (!~, !=) and a new TestSingletonClassAssignTarget;
go vet, the full suite and the 100% merged-coverage gate stay green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 76c51bf into main Aug 15, 2026
11 checks passed
@tannevaled
tannevaled deleted the fix/def-nmatch-and-singleton-assign branch August 15, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant