Skip to content

Add singleton classes, paren-less command args, and panic hardening - #2

Merged
tannevaled merged 1 commit into
mainfrom
frontend-command-args-singleton
Jun 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
frontend-command-args-singleton

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Closes the top three measured front-end gaps against Rails and Ruby's standard library.

P1 — singleton class (class << self / class << expr)

class << target; body; end now parses to a new ast.SingletonClassDef{Target, Body} instead of erroring with "singleton class … is not supported". Supports the idiomatic class << self class-method block, class << obj on a local, and arbitrary expression targets (class << obj.thing).

MRI-verified repros now passing:

  • class << self; def x; 1; end; end
  • o = Object.new; class << o; def y; 2; end; end

P2 — paren-less command calls with arguments

parseCommandArgs now reuses parseOneCallArg, so a command call accepts the same forms a parenthesized call does:

  • keyword/hash args without parens: delegate :a, :b, to: :c, validates :x, presence: true, render json: x, status: :ok
  • multiple positional args: foo a, b, c, puts x, y
  • splat / double-splat / block-pass: foo *args, foo **opts, foo &blk
  • mixed with a lambda: has_many :posts, -> { order(:id) }, dependent: :destroy
  • as a statement and as an assignment RHS: x = foo a, b

canStartCommandArg recognizes the LABEL and hugging * / ** / & starters. A trailing do…end binds to the command call (MRI precedence) while a braced {…} block still binds to the nearest call.

P3 — never-panic robustness

  • Parse converts any non-parseError internal panic into a clean parse error instead of re-panicking.
  • negateLiteral now handles a BignumLit operand. This fixes a real runtime.TypeAssertionError crash on a negated integer literal that overflows int64 (e.g. -9999999999999999999999999999999) — the root cause of every panic observed on real Rails sources.

Measured parse-acceptance delta

Full rails/ checkout (3422 .rb files):

accepted panics
before 47.1% 5
after 69.6% 0

Ruby stdlib (1511 files): 49.4% → 55.9%, 0 panics throughout.

Quality

  • 100% statement coverage (CI gate)
  • go vet ./... clean, CGO-free, no byte-order/arch assumptions

🤖 Generated with Claude Code

Close the top three real-world front-end gaps measured against Rails and
Ruby's standard library.

P1 — singleton-class open form. `class << target; body; end` now parses to
a new ast.SingletonClassDef{Target, Body} instead of erroring. Covers the
idiomatic `class << self` class-method block as well as `class << obj` and
arbitrary expression targets.

P2 — paren-less command calls with arguments. parseCommandArgs now reuses
parseOneCallArg, so a command call accepts the same keyword/hash pairs
(`render json: x, status: :ok`), splats, double-splats, block-pass and
multiple positional arguments a parenthesized call does — as a statement and
as an assignment RHS (`x = foo a, b`). canStartCommandArg recognizes the
LABEL and hugging `*`/`**`/`&` starters. A trailing `do…end` now binds to
the command call (MRI precedence) while a braced block still binds to the
nearest call.

P3 — never-panic robustness. Parse converts any non-parseError internal
panic into a clean parse error instead of re-panicking, and negateLiteral
handles a BignumLit operand — fixing the runtime TypeAssertionError crash on
negative integer literals that overflow int64 (e.g.
-9999999999999999999999999999999), the root cause of every panic observed on
real Rails sources.

Measured parse-acceptance delta (full rails/ checkout, 3422 .rb files):
47.1% → 69.6% accepted, 5 panics → 0. Ruby stdlib: 49.4% → 55.9%.

100% statement coverage; go vet clean; CGO-free.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit a69d0a5 into main Jun 26, 2026
9 checks passed
@tannevaled
tannevaled deleted the frontend-command-args-singleton branch June 26, 2026 07:18
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