Skip to content

Match MRI 4.0 Symbol#inspect quoting rules - #513

Merged
tannevaled merged 1 commit into
mainfrom
feat/agent-symbol
Aug 30, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/agent-symbol

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Symbol#inspect was quoting many symbols that MRI prints bare. This reworks the bare-vs-quoted predicate to mirror MRI's rb_enc_symname_type.

A symbol prints bare when it is:

  • an operator method name (:+, :<=>, :[]=, :`, :!~, …),
  • an identifier optionally prefixed by @/@@/$ (with MRI's special-global-variable forms for $: :$~, :$-w, :$1234, …),
  • such an identifier with a class-appropriate trailing ?/!/=.

Any byte >= 0x80 of a valid-UTF-8 body counts as an identifier character, so non-ASCII letters now print bare (:äöü, :测, :🦊, :±, :a±b). A body that is not valid UTF-8 (a binary byte string) stays quoted (:"foo\xA4").

A separate, stricter predicate (isSymLabel) now drives the Ruby 3.4+ hash short-form name:, which — unlike Symbol#inspect — quotes operator, prefixed and attribute-setter names. This fixes keys such as :+, :@x, :foo= that were wrongly emitted as bare labels, while non-ASCII labels (あ:) print bare.

Deltas (rubyspec-corpus)

  • core/symbol/inspect_spec: fail 35 -> 2 (both remaining need per-symbol encoding tracking for non-ASCII-compatible / dummy encodings — out of scope, Symbol is a plain Go string with no encoding tag).
  • core/hash/inspect_spec: fail 12 -> 11 ("can be evaled" now passes).
  • No regressions in core/symbol/*, core/array/inspect, core/kernel/inspect.

Verified byte-for-byte against ruby 4.0.x (UTF-8 default external) over the full spec table plus operator, global, attrset, prefix, non-ASCII and binary cases.

Scope

Changes confined to internal/object/object.go (+ tests). Out of scope: Symbol#to_proc (Proc internals), shared start_with/end_with (to_str/regexp/encoding), Symbol#to_s encoding — none are self-contained Symbol-inspect fixes.

Tests / gates

  • New internal/vm/symbol_inspect_conformance_test.go and predicate cases in internal/object/object_test.go.
  • go test ./... green; GOOS=wasip1 GOARCH=wasm go build ./... OK; gofmt -l clean.
  • Merged coverage (-coverpkg across ./internal/...) = 100.0%; all new functions 100%.

🤖 Generated with Claude Code

Symbol#inspect quoted many symbols that MRI prints bare. Rework the
bare-vs-quoted predicate to mirror MRI's rb_enc_symname_type: a symbol
prints bare when it is an operator method name, an identifier (optionally
@/@@/$-prefixed, with the special-global-variable forms for $), or such an
identifier with a class-appropriate trailing ? ! or =. Any byte >= 0x80 of
a valid-UTF-8 body counts as an identifier character, so non-ASCII letters
now print bare (:äöü, :测, :🦊, :±); a body that is not valid UTF-8 (a binary
byte string) stays quoted.

Also add a dedicated, stricter predicate (isSymLabel) for the Ruby 3.4+
hash short-form `name:`, which unlike Symbol#inspect quotes operator,
prefixed, and attribute-setter names — fixing keys such as :+, :@x and :foo=
that were wrongly printed as bare labels.

core/symbol/inspect_spec: fail 35 -> 2 (remaining two need per-symbol
encoding tracking for non-ASCII-compatible/dummy encodings). core/hash
inspect "can be evaled" now passes. Verified byte-for-byte against ruby
4.0.x for the full spec table plus operator, global, attrset, prefix,
non-ASCII and binary cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 3bc6b17 into main Aug 30, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-symbol branch August 30, 2026 21:57
tannevaled added a commit that referenced this pull request Aug 30, 2026
The Marshal conformance test's sym_encoded_roundtrip case expected the
non-ASCII symbol :€x to inspect as the quoted :"€x", which was rbgo's
behaviour when that test was written but not MRI's. It was authored in
parallel with the Symbol#inspect fix (#513) that made non-ASCII symbols
print bare (:€x, matching MRI 4.0), so once both merged the expectation
was stale and failed. Assert the correct MRI output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled added a commit that referenced this pull request Aug 30, 2026
* Bump ruby/spec FLOOR 16990 -> 17270

Lock in a second cluster of conformance merges: Symbol#inspect quoting,
full-Unicode regex POSIX classes (go-regexp/engine v0.1.2), Marshal
dump/load, Numeric#step + Enumerator::ArithmeticSequence, and the Time
constructor argument forms. Measured total is 17316 passing examples
(files loaded 2162, failed 44); the floor is set below that with margin
for slower CI hardware.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Fix a stale Symbol-inspect expectation in the Marshal conformance test

The Marshal conformance test's sym_encoded_roundtrip case expected the
non-ASCII symbol :€x to inspect as the quoted :"€x", which was rbgo's
behaviour when that test was written but not MRI's. It was authored in
parallel with the Symbol#inspect fix (#513) that made non-ASCII symbols
print bare (:€x, matching MRI 4.0), so once both merged the expectation
was stale and failed. Assert the correct MRI output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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