Repository navigation
Struct/Data: advance MRI 4.0.6 conformance (keyword auto-detect, each_pair, dig, to_h, inspect, recursive hash) - #540
Merged
Merged
Conversation
…_pair, dig, to_h, inspect) Struct#initialize (keyword_init unset) now takes a lone Hash whose keys all name members as keyword init (Ruby 3.2 auto-detect), and is private. Struct#each_pair yields a single [name, value] Array (Hash#each style) so an Enumerator consumer receives the pair whole. Struct#dig with a non-member name returns nil instead of raising NameError. Struct#to_h with a block coerces the returned pair via #to_ary (never #to_a) and names the real class in its TypeError. deconstruct_keys reports "expected Array or nil" and names the real class in the #to_int TypeError. Struct/Data #inspect omit the class name for a class nested in an anonymous namespace (permanent-classpath check), and a recursive anonymous Data renders the member class as "#<Class:0x…>". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rb_struct_hash runs under rb_exec_recursive_outer, which on a cycle unwinds to the outermost struct and hashes from its class alone (members skipped). Replicate that: structHashWalk folds member hashes while tracking the path, and any back-edge makes structHash return the class-only value — so #eql? recursive structs (which short-circuit on the shared cyclic member) hash alike, matching core/struct/hash_spec "recursive structs". Adds struct_residuals_test.go covering the changed branches. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 1, 2026
Locks in #535 (String methods: index/casecmp/chomp/gsub/scan/tr/... ~+110), #536 (IO/StringIO reader+writer), #538 (Array#[]= auto-grow + mutators), #539 (Range + Comparable), #540 (Struct + Data), #541 (Time). Measured 17983 passing on the pinned corpus, up from 17654. 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.
Advances MRI Ruby 4.0.6 conformance for
core/struct/*andcore/data/*.Corpus (rubyspec) result went from 230 pass / 18 fail+error to 246 pass / 2 fail across the two suites (16 examples fixed); the 2 residual failures are out of scope (see below).
All work is confined to
internal/vm/struct.go,internal/vm/data.go, and tests.Fixes
Struct#initializekeyword_init auto-detect (Ruby 3.2) — whenkeyword_init:is unset, a loneHashargument whose keys all name members is taken as keyword initialisation; a Hash with any non-member or non-Symbol key stays a positional value. MRI decides this from the caller's keyword flag, which our calling convention does not carry to a native method, so we approximate by matching keys against members (preserves e.g.Struct.new(:a).new({b: 1})as positional).Struct#initializeis now private (private_instance_methodsincludes:initialize).Struct#each_pairyields a single[name, value]Array per pair (Hash#each style), so an Enumerator consumer such aseach_pair.map { |v| v }receives the pair whole.Struct#digwith a name that is not a member returnsnilinstead of raisingNameError(unlike#[]).Struct#to_hwith a block coerces the returned pair via#to_ary(never#to_a) and names the real class in itsTypeError.Struct#deconstruct_keysreportsexpected Array or nil, and names the real class in the#to_intconversionTypeError.Struct#to_s/Data#to_somit the class name for a class nested in an anonymous namespace (permanent-classpath check), matching MRI'srb_class_path_cached. A recursive anonymousDatarenders the member class as#<Class:0x…>.Struct#hashfor recursive structs collapses to a class-only value, replicating MRI'srb_exec_recursive_outer(unwind to the outermost struct, hash from its class alone). Necessary because#eql?recursive structs must hash alike.Out of scope (reported, not fixed)
The 2 remaining corpus failures —
Struct#hash/Data#hash"returns different hashes for different classes" — are not hash bugs (the hashes are genuinely different). They fail because these specs usex.should != y, and the VM compilesa != bas!(a == b)without dispatching a user-defined#!=, so the spec harness'sShouldProxy#==runs and raises. This is compiler/operator-dispatch machinery outsidestruct.go.Verification
go test ./internal/vm/green;go test ./...green.GOOS=wasip1 GOARCH=wasm go build ./...OK.gofmt -lclean on changed files.struct.goanddata.gois at 100.0% coverage under the merged (-coverpkg ./internal/...) profile; repo total unchanged at ~99.9%.🤖 Generated with Claude Code