Repository navigation
Match MRI 4.0 Symbol#inspect quoting rules - #513
Merged
Merged
Conversation
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
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>
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.
Summary
Symbol#inspectwas quoting many symbols that MRI prints bare. This reworks the bare-vs-quoted predicate to mirror MRI'srb_enc_symname_type.A symbol prints bare when it is:
:+,:<=>,:[]=,:`,:!~, …),@/@@/$(with MRI's special-global-variable forms for$::$~,:$-w,:$1234, …),?/!/=.Any byte
>= 0x80of 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-formname:, which — unlikeSymbol#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,Symbolis a plain Go string with no encoding tag).core/hash/inspect_spec: fail 12 -> 11 ("can be evaled" now passes).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), sharedstart_with/end_with(to_str/regexp/encoding),Symbol#to_sencoding — none are self-contained Symbol-inspect fixes.Tests / gates
internal/vm/symbol_inspect_conformance_test.goand predicate cases ininternal/object/object_test.go.go test ./...green;GOOS=wasip1 GOARCH=wasm go build ./...OK;gofmt -lclean.-coverpkgacross./internal/...) = 100.0%; all new functions 100%.🤖 Generated with Claude Code