Repository navigation
fix(parser): def !~ operator method, and class << with an assignment target - #17
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two
def/classforms MRI accepts were rejected by the parser:def !~(other)— the not-match operator method.!~lexes as oneNMATCHtoken and is already a valid binary operator, butparseDefNamelistedMATCH(=~) and notNMATCH, sodef !~failed with "expected method name after def".!=was also untested (thoughNEQwas 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 withparseExprOrAssignrather thanparseTernary, which stopped at the=.Both are exercised by ruby/spec (
Kernel#!~,Kernel#public_send), whose spec files failed to even load in the downstreamgo-embedded-rubyinterpreter because of these parse errors.Tests
TestOperatorMethodDefgains!~and!=.TestSingletonClassAssignTarget(target is anIvarAssign).go vet ./..., the full suite, and the 100% merged-coverage gate stay green;class << self/<< obj/<< obj.thingstill parse.🤖 Generated with Claude Code