Skip to content

Commit bbbed8e

Browse files
tannevaledclaude
andauthored
Ruby 4.0.9: the version rbgo reports (#882)
* Ruby 4.0.9: the version rbgo reports, and the numbered parameters RUBY_VERSION moves from 3.4.1 to 4.0.9, and the one behaviour that could not land without it lands with it. ## Why these two are one commit compiler.go said so already: hiding `_1` from a Binding "belongs with the RUBY_VERSION bump". Below 4.0 ruby/spec asserts the OPPOSITE -- language/numbered_parameters_spec.rb:93 is `ruby_version_is ""..."4.0"` and pins `binding.local_variables == [:_1]` -- so doing it alone would have traded four passing examples for four failing ones. ## The asymmetry is the whole change `_1` leaves the LOCAL TABLE and stays in #parameters: proc { _1 }.parameters # [[:opt, :_1]] -- UNGATED -> { _1; binding.local_variables }.call("a") # [:_1] below 4.0, [] from 4.0 numbered_parameters_spec.rb:85 carries no version guard, so blanking b.params as well would trade four examples for two. `it` is blanked from BOTH, because MRI gives it no name in #parameters either. So: b.locals for both kinds, b.params for `it` only. ## Refusing by NAME, before any lookup MRI tests rb_numparam_id_p at the TOP of #local_variable_get, #local_variable_set and #local_variable_defined? (proc.c v4.0.9:549, 602, 649): if (rb_numparam_id_p(lid)) { rb_name_err_raise("numbered parameter '%1$s' is not a local variable", ...) } Two consequences that are easy to miss and are both tested: - it raises in a binding that has NO numbered parameter, and at the top level. `_1` is not a local being hidden; it is not a local variable NAME. - #local_variable_defined? RAISES rather than answering false. "Not defined" is the natural reading and the wrong one. And it uses rb_numparam_id_p, NOT rb_implicit_param_p (proc.c:517-521), which also covers `it`. That narrowing is deliberate in MRI and necessary here: `it` is a LEGAL local variable name -- `it = 5` compiles -- so widening the refusal would break every binding holding a variable called `it`. There is a control for it, and for the `_0` / `_10` / `_` boundary. ## What the bump breaks, measured `go test ./...` over the whole repository: FOUR assertions, every one of them a deliberate pin of the pre-4.0 behaviour, and nothing else in a 210-second VM suite. internal/compiler TestImplicitBlockParamsAreHidden "want the numbered names kept" internal/vm TestImplicitItIsInvisible "_1 is a binding local" internal/vm TestImplicitParametersAreNotLocalVariables subtest: "while _1 stays visible at the version rbgo reports" internal/vm TestPBRbConfigKeys the version string Each is updated to the 4.0 behaviour with its comment rewritten, not flipped silently. The third gains a case for the point that `it` and `_1` are refused by DIFFERENT messages. The fourth raises a question this commit does not answer: MRI may report the API version ("4.0.0") rather than the full one for RbConfig::CONFIG["ruby_version"]. Nothing in ruby/spec asserts that key, so the corpus cannot settle it. Filed as #878 rather than changed on a hunch. Refs #799 Refs #878 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * BASELINE re-recorded at 4.0.9, on the machine that enforces it Recorded by the rubyspec-baseline lane (#877) on the pinned ubuntu-24.04 -- the same runner the ratchet gates on -- and downloaded as its artefact. Not recorded here: this machine reads +9 against CI for no change in the code. 23,511 -> 23,673 passing examples ## The refusal was exercised on the real case first The lane was dispatched WITHOUT -absorb before it was dispatched with it, because the gate added in #876 had only ever refused a synthetic loss: re-record: 2206 files measured, 2206 in the baseline being replaced -- REGRESSED (11) -- core/objectspace/_id2ref_spec.rb: 0 passing, baseline 10 (-10) core/set/flatten_merge_spec.rb: 0 passing, baseline 3 (-3) ... ::error::REFUSING to re-record: 11 file(s) went backwards -- named above Both of the lane's deliberate asymmetries held on that run: the diffstat step ran (it carries always()) and the artefact step was SKIPPED (it does not), so no unchanged BASELINE was offered as "the re-recorded baseline". The second dispatch passed -absorb, and the baseline now carries the stamp: # ⛔ ABSORBED 11 file(s) that went backwards, recorded with -absorb on 2026-11-03: # core/gc/config_spec.rb: 7 passing, baseline 8 (-1) # ... Six of the eleven are guards CLOSING -- examples 4.0 stops asking for, each with a `ruby_version_is ""..."4.0"` site in the census -- and not defects. ## ⛔ What comparing the SETS found, which the counts hid The local sweep predicted 13 files going backwards; CI named 11. Both missing entries are informative: - language/numbered_parameters_spec.rb is absent because THIS BRANCH fixes it. Independent confirmation in CI of the +4 measured locally. - language/variables_spec.rb is absent because the baseline was STALE. CI reported "118 passing, baseline 115 (+3)" -- an improvement -- while the file has passed 119 since #871 and the move genuinely costs one example there. A real regression reported as a gain. That is a structural blind spot in the gate: a per-file floor cannot see a regression smaller than the file's unbanked improvement. Filed as #881. It is the exact complement of #876, which stops a re-record banking a LOSS; this is the cost of not banking a WIN -- and it existed because until #877 there was no correct way to re-record at all. This fresh measurement clears the accumulated slack as a side effect. ## README TestReadmeConformanceCountMatchesTheBaseline named all three stale sites and the new figure, which is how the README was updated rather than by hand. The dated table is left as the 3.4.1 sweep it is and now says so. Refs #799 Refs #881 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 280a339 commit bbbed8e

10 files changed

Lines changed: 329 additions & 161 deletions

‎README.md‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue)](LICENSE)
77
[![Go](https://img.shields.io/github/go-mod/go-version/go-embedded-ruby/ruby?label=go&color=00ADD8)](https://go.dev/dl/)
88
[![Release](https://img.shields.io/github/v/release/go-embedded-ruby/ruby?label=release&color=blue)](https://github.com/go-embedded-ruby/ruby/releases/latest)
9-
[![ruby/spec](https://img.shields.io/badge/ruby%2Fspec-23%2C511%20examples%20passing-1a7f37)](#runtime-conformance--rubyspec)
9+
[![ruby/spec](https://img.shields.io/badge/ruby%2Fspec-23%2C673%20examples%20passing-1a7f37)](#runtime-conformance--rubyspec)
1010

1111
**A Ruby interpreter written in pure Go, with cgo disabled** — so you can embed it
1212
in a Go program with `import "github.com/go-embedded-ruby/ruby"`, or ship it as a
1313
single static binary that cross-compiles wherever Go does, with no C toolchain and
1414
no libruby.
1515

16-
**How complete is it?** It runs **23,511** of ruby/spec's `language/` + `core/`
16+
**How complete is it?** It runs **23,673** of ruby/spec's `language/` + `core/`
1717
examples ([what that counts](#runtime-conformance--rubyspec)) — a large and growing
1818
subset of the language, and **not** a drop-in replacement for CRuby. Read
1919
[What does not work yet](#what-does-not-work-yet) before you depend on it; the
@@ -153,6 +153,14 @@ writing. Only the baseline is machine-checked against this file
153153
from the sweep named below and are not derivable from the baseline, which
154154
records passing counts and nothing else.
155155

156+
⛔ **The table is a sweep taken at `RUBY_VERSION` 3.4.1**, before the move to
157+
4.0.9. Its rows are left as they were measured rather than rewritten, because
158+
they come from one dated run and are not derivable from the baseline; the badge
159+
and the summary above count the current `BASELINE` and so already reflect 4.0.9.
160+
The move was measured separately — both engines built from one commit minus the
161+
version string — at **+144 passing and 27 examples that went red**
162+
([#799](https://github.com/go-embedded-ruby/ruby/issues/799)).
163+
156164
Measured 2026-09-28 on `862a9f3`, darwin/arm64, against the corpus pinned at
157165
`SPEC_SHA=87b1631992bd00cf0c4934474766d54dad088191`, on an isolated snapshot of
158166
it so no concurrent run could swap the shim underneath, and reached through a
@@ -763,7 +771,7 @@ Otherwise:
763771

764772
| | how it differs from MRI 4.0.5 |
765773
| --- | --- |
766-
| `RUBY_VERSION` | rbgo reports `"3.4.1"`; the differential oracle it is developed against is MRI 4.0.5, and the latest MRI release is 4.0.9 (2026-10-23). The Ruby 4.0 **`Ruby` namespace** *is* implemented — all nine of `Ruby::{VERSION,RELEASE_DATE,PLATFORM,PATCHLEVEL,REVISION,COPYRIGHT,ENGINE,ENGINE_VERSION,DESCRIPTION}` are the **same objects** as their `RUBY_`-prefixed globals, as `version.c` defines them, so `Ruby::VERSION.equal?(RUBY_VERSION)` is `true`. The conformance shim resolves `ruby_version_is` at the reported `3.4.1`, so the ten examples asserting that in `core/builtin_constants` are **not counted by the gate**: measured here, that file yields 17 at 3.4.1 and 27 at 4.0.9 ([#799](https://github.com/go-embedded-ruby/ruby/issues/799)) |
774+
| `RUBY_VERSION` | rbgo reports `"4.0.9"`, the latest MRI release (2026-10-23). The Ruby 4.0 **`Ruby` namespace** *is* implemented — all nine of `Ruby::{VERSION,RELEASE_DATE,PLATFORM,PATCHLEVEL,REVISION,COPYRIGHT,ENGINE,ENGINE_VERSION,DESCRIPTION}` are the **same objects** as their `RUBY_`-prefixed globals, as `version.c` defines them, so `Ruby::VERSION.equal?(RUBY_VERSION)` is `true`. The move from `3.4.1` was measured before it was made, with both engines built from one commit minus the version string: **+144 passing** over `core` and `language`, and **27 examples that went red**, which no pass total shows — see [#799](https://github.com/go-embedded-ruby/ruby/issues/799) for the list of what each of the 27 needs |
767775
| `Numeric#to_int` | not defined — `Complex(2.9, 0).to_int` raises `NoMethodError`; MRI returns `2` |
768776
| `File::Stat#==` | `a == b` is `false` for two stats of the same file (MRI: `true`); `a.==(b)` answers `true` |
769777
| `File#stat` on a file unlinked while open | raises `Errno::ENOENT`; MRI answers from the open descriptor. rbgo's streams are buffered by path and hold no descriptor |
@@ -1248,7 +1256,7 @@ specification of the language — through `rbgo` under a minimal MSpec-compatibl
12481256
shim, and gates CI on a **per-file** baseline
12491257
([`scripts/conformance/rubyspec/`](scripts/conformance/rubyspec/), in
12501258
`BASELINE`). No file may pass fewer examples than its record or stop loading, so
1251-
measured language conformance moves in one direction; the total, **23,511**, is
1259+
measured language conformance moves in one direction; the total, **23,673**, is
12521260
a derived summary rather than the thing gated. Run it with
12531261
`scripts/conformance/rubyspec/run.sh`, and see *Runtime conformance* under
12541262
*Status* for the full breakdown.

‎internal/compiler/compiler.go‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,12 +2202,22 @@ func blockParamsAreImplicit(blk *ast.Block) bool {
22022202
// name AFTER the body is compiled: resolution during the body used the real
22032203
// name, and the ISeq that remains carries none.
22042204
//
2205-
// The numbered parameters `_1`..`_9` are deliberately NOT hidden. They are named
2206-
// in #parameters ([[:opt, :_1]]) and, for the Ruby version rbgo reports
2207-
// (RUBY_VERSION 3.4.1), they are visible to a Binding too — ruby/spec pins that
2208-
// under `ruby_version_is ""..."4.0"` and pins the hiding only from 4.0. Hiding
2209-
// them here would be answering a question rbgo has not yet said it is answering;
2210-
// it belongs with the RUBY_VERSION bump.
2205+
// ⛔ THE NUMBERED PARAMETERS ARE HIDDEN FROM b.locals AND NOT FROM b.params, and
2206+
// that asymmetry is the whole of Ruby 4.0's change here. `_1` leaves
2207+
// Binding#local_variables but STAYS in Proc#parameters:
2208+
//
2209+
// proc { _1 }.parameters # => [[:opt, :_1]] -- ungated, every version
2210+
// -> { _1; binding.local_variables }.call("a")
2211+
// # => [:_1] below 4.0, [] from 4.0
2212+
//
2213+
// numbered_parameters_spec.rb:85 ("affects block parameters") carries no version
2214+
// guard at all, so blanking b.params as well would trade four examples for two.
2215+
// `it` is blanked from BOTH, because MRI gives it no name in #parameters either
2216+
// (`-> { it }.parameters` is [[:req]], NAMELESS).
2217+
//
2218+
// This was held back until the RUBY_VERSION bump, correctly: below 4.0
2219+
// ruby/spec asserts the OPPOSITE, under `ruby_version_is ""..."4.0"`. The two
2220+
// land together.
22112221
//
22122222
// ⛔ BOTH KINDS ARE RECORDED, hidden or not. Ruby 4.0 adds
22132223
// Binding#implicit_parameters, #implicit_parameter_get and
@@ -2229,13 +2239,13 @@ func hideImplicitBlockParams(b *builder, blk *ast.Block, positionals []string) {
22292239
// gate named it, which is the right way to find out.
22302240
for i, name := range positionals {
22312241
b.markImplicitParam(i, name)
2232-
if name != "it" {
2233-
continue
2234-
}
2242+
// Out of the local table: both kinds, from 4.0.
22352243
if i < len(b.locals) {
22362244
b.locals[i] = ""
22372245
}
2238-
if i < len(b.params) {
2246+
// Out of #parameters: `it` only. A numbered parameter keeps its name
2247+
// there, which numbered_parameters_spec.rb:85 asserts with no guard.
2248+
if name == "it" && i < len(b.params) {
22392249
b.params[i] = ""
22402250
}
22412251
}

‎internal/compiler/wave29_kwargs_test.go‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,18 @@ func TestImplicitBlockParamsAreHidden(t *testing.T) {
360360
if len(writtenIt.Params) != 1 || writtenIt.Params[0] != "it" {
361361
t.Errorf("f { |it| it }: Params = %q, want [\"it\"]", writtenIt.Params)
362362
}
363-
// The numbered parameters keep theirs, in both tables.
363+
// ⛔ THE NUMBERED PARAMETERS SPLIT THE TWO TABLES, and this asymmetry is the
364+
// whole of Ruby 4.0's change. They keep their names in Params, because
365+
// `proc { _1 }.parameters` is [[:opt, :_1]] under no version guard at all
366+
// (numbered_parameters_spec.rb:85), and lose them in Locals, because from
367+
// 4.0 they are not local variables (:112-135). `it` loses both; a numbered
368+
// parameter loses one.
364369
np := blockOf(t, "f { _1 + _2 }")
365370
if len(np.Params) != 2 || np.Params[0] != "_1" || np.Params[1] != "_2" {
366-
t.Errorf("f { _1 + _2 }: Params = %q, want [\"_1\" \"_2\"]", np.Params)
371+
t.Errorf("f { _1 + _2 }: Params = %q, want [\"_1\" \"_2\"] -- #parameters is ungated", np.Params)
367372
}
368-
if len(np.Locals) < 2 || np.Locals[0] != "_1" || np.Locals[1] != "_2" {
369-
t.Errorf("f { _1 + _2 }: Locals = %q, want the numbered names kept", np.Locals)
373+
if len(np.Locals) < 2 || np.Locals[0] != "" || np.Locals[1] != "" {
374+
t.Errorf("f { _1 + _2 }: Locals = %q, want the numbered names blanked from 4.0", np.Locals)
370375
}
371376
}
372377

‎internal/vm/binding.go‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func (vm *VM) registerBinding() {
292292
cBinding.define("local_variable_get", func(vm *VM, self object.Value, args []object.Value, _ *Proc) object.Value {
293293
b := self.(*Binding)
294294
name := vm.bindingVarName(args[0])
295+
refuseNumberedParam(name)
295296
i := b.slotOf(name)
296297
if i < 0 {
297298
raise("NameError", "local variable '%s' is not defined for %s", name, b.ToS())
@@ -302,6 +303,7 @@ func (vm *VM) registerBinding() {
302303
cBinding.define("local_variable_set", func(vm *VM, self object.Value, args []object.Value, _ *Proc) object.Value {
303304
b := self.(*Binding)
304305
name := vm.bindingVarName(args[0])
306+
refuseNumberedParam(name)
305307
if i := b.slotOf(name); i >= 0 {
306308
// The write lands where the name LIVES, which for a binding taken inside a
307309
// block is an ANCESTOR env. Writing b.env.slots[i] instead put the value in
@@ -318,7 +320,12 @@ func (vm *VM) registerBinding() {
318320
return args[1]
319321
})
320322
cBinding.define("local_variable_defined?", func(vm *VM, self object.Value, args []object.Value, _ *Proc) object.Value {
321-
return object.Bool(self.(*Binding).slotOf(vm.bindingVarName(args[0])) >= 0)
323+
name := vm.bindingVarName(args[0])
324+
// ⛔ RAISES, it does not answer false. MRI puts the refusal before the
325+
// lookup (proc.c v4.0.9:649), so this is not "no such local" — it is
326+
// "that is not the kind of question this method answers".
327+
refuseNumberedParam(name)
328+
return object.Bool(self.(*Binding).slotOf(name) >= 0)
322329
})
323330

324331
// Ruby 4.0's implicit-parameter trio (proc.c v4.0.9:680-783). They are the
@@ -388,15 +395,41 @@ func copyImplicit(m map[string]int) map[string]int {
388395
return out
389396
}
390397

391-
// isImplicitParamName is MRI's rb_implicit_param_p: `it`, or `_` followed by a
392-
// single digit 1..9. `_0` and `_10` are ordinary locals.
398+
// isImplicitParamName is MRI's rb_implicit_param_p (proc.c v4.0.9:517-521):
399+
// `it`, or `_` followed by a single digit 1..9. `_0` and `_10` are ordinary
400+
// locals.
393401
func isImplicitParamName(name string) bool {
394-
if name == "it" {
395-
return true
396-
}
402+
return name == "it" || isNumberedParamName(name)
403+
}
404+
405+
// isNumberedParamName is MRI's rb_numparam_id_p (proc.c v4.0.9:511-515), which
406+
// tests `_1`..`_9` and NOT `it`.
407+
//
408+
// ⛔ THE TWO PREDICATES ARE NOT INTERCHANGEABLE, and MRI uses this narrower one
409+
// in all three of Binding's local-variable methods (proc.c:549, 602, 649) while
410+
// rb_implicit_param_p is used elsewhere. The reason is not a detail: `it` is a
411+
// LEGAL local variable name in Ruby — `it = 5` compiles — so
412+
// `binding.local_variable_get(:it)` must answer normally, while `_1` can never
413+
// be a local and is refused. Widening the refusal to rb_implicit_param_p would
414+
// break every binding that happens to hold a variable called `it`.
415+
func isNumberedParamName(name string) bool {
397416
return len(name) == 2 && name[0] == '_' && name[1] >= '1' && name[1] <= '9'
398417
}
399418

419+
// refuseNumberedParam is the guard MRI puts at the top of #local_variable_get,
420+
// #local_variable_set and #local_variable_defined? (proc.c v4.0.9:549, 602,
421+
// 649), from Ruby 4.0.
422+
//
423+
// ⛔ IT TESTS THE NAME, NOT THE BINDING, and fires BEFORE any lookup — so
424+
// `binding.local_variable_get(:_1)` raises this even in a binding that has no
425+
// numbered parameter at all, and even at the top level. `_1` is not a local
426+
// variable that happens to be hidden; it is not a local variable name.
427+
func refuseNumberedParam(name string) {
428+
if isNumberedParamName(name) {
429+
raise("NameError", "numbered parameter '%s' is not a local variable", name)
430+
}
431+
}
432+
400433
// implicitParameterNames is bind_implicit_parameters (proc.c v4.0.9:680): [:it]
401434
// when `it` is this scope's implicit parameter, otherwise the numbered ones in
402435
// order. A block has one kind or the other and never both — `proc { |x| _1 }` is

‎internal/vm/binding_implicit_params_test.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,18 @@ func TestImplicitParametersAreNotLocalVariables(t *testing.T) {
227227
`rescue NameError => e; r = e.message; end }; r`,
228228
want: `local variable 'it' is not defined for #<Binding>`,
229229
}, {
230-
name: "while _1 stays visible at the version rbgo reports",
230+
name: "and _1 is hidden the same way from 4.0",
231231
src: `r = nil; [1].each { _1; r = binding.local_variables.include?(:_1) }; r.inspect`,
232-
want: `true`,
232+
want: `false`,
233+
}, {
234+
// ⛔ But NOT the same way through local_variable_get. `it` is a legal
235+
// local variable name, so asking for it gets the ordinary "not defined"
236+
// above; `_1` can never be one, and MRI refuses it by name before any
237+
// lookup (proc.c v4.0.9:549). Two different messages, deliberately.
238+
name: "though with a different refusal, because _1 is not a NAME a local can have",
239+
src: `r = nil; [1].each { _1; begin; binding.local_variable_get(:_1); ` +
240+
`rescue NameError => e; r = e.message; end }; r`,
241+
want: `numbered parameter '_1' is not a local variable`,
233242
}} {
234243
t.Run(tc.name, func(t *testing.T) {
235244
if got := evalString(t, tc.src); got != tc.want {
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package vm
2+
3+
import "testing"
4+
5+
// Ruby 4.0 takes the numbered parameters out of Binding's local-variable API
6+
// (language/numbered_parameters_spec.rb:112-135, opened by `ruby_version_is
7+
// "4.0"`; the block at :93-110 asserts the opposite below it and closes).
8+
//
9+
// ⛔ THE REFUSAL IS ABOUT THE NAME, NOT THE BINDING. MRI tests
10+
// rb_numparam_id_p(lid) at the TOP of each of the three methods, before any
11+
// lookup happens (proc.c v4.0.9:549, 602, 649), so `_1` raises in a binding
12+
// that has no numbered parameter at all. `_1` is not a local variable that is
13+
// being hidden; it is not a local variable name.
14+
func TestNumberedParametersAreNotLocalVariables(t *testing.T) {
15+
const msg = "numbered parameter '_1' is not a local variable"
16+
for _, tc := range []struct{ name, src, want string }{
17+
{
18+
"local_variable_get raises",
19+
`begin; -> { _1; binding.local_variable_get(:_1) }.call("a"); rescue NameError => e; e.message; end`,
20+
msg,
21+
},
22+
{
23+
"local_variable_set raises",
24+
`begin; -> { _1; binding.local_variable_set(:_1, "b") }.call("a"); rescue NameError => e; e.message; end`,
25+
msg,
26+
},
27+
{
28+
// RAISES rather than answering false, which is the easy one to get
29+
// wrong: "not defined" is the natural reading and the wrong one.
30+
"local_variable_defined? raises rather than answering false",
31+
`begin; -> { _1; binding.local_variable_defined?(:_1) }.call("a"); rescue NameError => e; e.message; end`,
32+
msg,
33+
},
34+
35+
// ⛔ Before the lookup: no numbered parameter is in scope anywhere here,
36+
// and it still raises. A guard placed after the lookup would answer
37+
// "local variable '_1' is not defined for ..." instead.
38+
{
39+
"it raises even where no numbered parameter exists",
40+
`begin; binding.local_variable_get(:_1); rescue NameError => e; e.message; end`,
41+
msg,
42+
},
43+
{
44+
"and for defined?, where false would otherwise be the answer",
45+
`begin; binding.local_variable_defined?(:_9); rescue NameError => e; e.message; end`,
46+
"numbered parameter '_9' is not a local variable",
47+
},
48+
49+
// ⛔ CONTROL: `it` is a LEGAL local variable name, so the refusal must
50+
// NOT widen to rb_implicit_param_p. MRI uses the narrower
51+
// rb_numparam_id_p in all three methods for exactly this reason.
52+
{
53+
"it is an ordinary local variable name and is not refused",
54+
`it = 5; binding.local_variable_get(:it).inspect`,
55+
"5",
56+
},
57+
{
58+
"and can be set through a binding",
59+
`it = 5; binding.local_variable_set(:it, 6); it.inspect`,
60+
"6",
61+
},
62+
{
63+
"and answers defined?",
64+
`it = 5; binding.local_variable_defined?(:it).inspect`,
65+
"true",
66+
},
67+
68+
// ⛔ CONTROL: the boundary of the name shape. `_0` and `_10` are
69+
// ordinary locals in MRI, so a refusal that tested "starts with _" or
70+
// "_ then digits" would reject names the program may legitimately use.
71+
{
72+
"_0 is an ordinary local",
73+
`_0 = 1; binding.local_variable_defined?(:_0).inspect`,
74+
"true",
75+
},
76+
{
77+
"_10 is an ordinary local",
78+
`_10 = 1; binding.local_variable_defined?(:_10).inspect`,
79+
"true",
80+
},
81+
{
82+
"a plain underscore is an ordinary local",
83+
`_ = 1; binding.local_variable_defined?(:_).inspect`,
84+
"true",
85+
},
86+
87+
// ⛔ CONTROL, and the trade this change must NOT make: #parameters is
88+
// ungated (numbered_parameters_spec.rb:85) and still names `_1`. Only
89+
// the LOCAL TABLE loses the name, never the parameter list -- which is
90+
// why the compiler blanks b.locals and leaves b.params alone.
91+
{
92+
"a proc still names its numbered parameters",
93+
`proc { _1 }.parameters.inspect`,
94+
"[[:opt, :_1]]",
95+
},
96+
{
97+
"and a lambda does too",
98+
`-> { _2 }.parameters.inspect`,
99+
"[[:req, :_1], [:req, :_2]]",
100+
},
101+
102+
// ⛔ CONTROL: they did not vanish, they moved. 4.0 gives them an API of
103+
// their own, and taking them out of one must not take them out of both.
104+
{
105+
"implicit_parameters still sees them",
106+
`-> { _1; binding.implicit_parameters }.call("a").inspect`,
107+
"[:_1]",
108+
},
109+
{
110+
"and implicit_parameter_get still reads them",
111+
`-> { _1; binding.implicit_parameter_get(:_1) }.call("a").inspect`,
112+
`"a"`,
113+
},
114+
} {
115+
t.Run(tc.name, func(t *testing.T) {
116+
if got := evalString(t, tc.src); got != tc.want {
117+
t.Errorf("%s\n got %q\nwant %q", tc.src, got, tc.want)
118+
}
119+
})
120+
}
121+
}
122+
123+
// #local_variables is tested through runSrc rather than evalString because
124+
// evalString wraps the source in `__v = begin … end`, and that assignment makes
125+
// `__v` a local of the ENCLOSING scope — which a binding taken inside a block
126+
// lists as well. The first run of the cases above read `[:__v]` where it wanted
127+
// `[]`: the numbered parameter was already gone and the harness was supplying
128+
// the remaining entry. An assertion written against that output would have
129+
// pinned my wrapper's name as Ruby behaviour.
130+
func TestNumberedParametersAreNotInLocalVariables(t *testing.T) {
131+
for _, tc := range []struct{ name, src, want string }{
132+
// The two examples numbered_parameters_spec.rb:113-116 opens at 4.0.
133+
{
134+
"one numbered parameter",
135+
`p(-> { _1; binding.local_variables }.call("a"))`,
136+
"[]",
137+
},
138+
{
139+
"several",
140+
`p(-> { _2; binding.local_variables }.call("a", "b"))`,
141+
"[]",
142+
},
143+
// ⛔ CONTROL: the list is not simply empty for every block. A real local
144+
// still appears, so the two cases above measure the hiding and not a
145+
// #local_variables that stopped working.
146+
{
147+
"a real local in the same shape still appears",
148+
`p(-> { x = 1; binding.local_variables }.call)`,
149+
"[:x]",
150+
},
151+
// ⛔ CONTROL: `it` is blanked from the local table the same way, and
152+
// this is the 4.0 behaviour rbgo already had before the version moved.
153+
{
154+
"it is not listed either",
155+
`p(-> { it; binding.local_variables }.call("a"))`,
156+
"[]",
157+
},
158+
} {
159+
t.Run(tc.name, func(t *testing.T) {
160+
if got := runSrc(t, tc.src); got != tc.want {
161+
t.Errorf("%s\n got %q\nwant %q", tc.src, got, tc.want)
162+
}
163+
})
164+
}
165+
}

‎internal/vm/kernel_introspect.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// function-local, which is how a CLI ends up printing a version the running VM
2222
// does not report.
2323
const (
24-
rubyVersion = "3.4.1"
24+
rubyVersion = "4.0.9"
2525
releaseDate = "2024-12-25"
2626
revision = "48d4efcb85000e1ebae42004e963b5d0cedddcf2"
2727
)

0 commit comments

Comments
 (0)