Repository navigation
Commit e06c688
vm: ObjectSpace._id2ref is deprecated in Ruby 4.0
One of the ten examples the version move needs, and the one the headline figure
most misrepresented.
`core/objectspace/_id2ref_spec.rb` reads `-10` between 3.4.1 and 4.0.9, which
looks like the largest single regression of the move. Its guards say otherwise:
```ruby
ruby_version_is "4.0" do # ONE example: "is deprecated"
ruby_version_is ""..."4.0" do # TEN examples asserting it works
```
So the −10 is ten examples 4.0 no longer asks for, and the work is the single
4.0 example. Measured on this branch: `pass=0 fail=1` →
**`pass=1 fail=0 error=0 skip=0`**.
## Upstream
gc.c at v4.0.9, `os_id2ref` (gc.c:2167) opens with
```c
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "ObjectSpace._id2ref is deprecated");
```
Category-gated, so an ordinary run stays silent: `Warning[:deprecated]` is off
by default. ruby/spec reaches it because the conformance shim turns the category
on (`spec_helper.rb:60`, with a comment already explaining exactly this), which
is also why the spec can assert it with a bare `complain(…)` and no
`verbose: true`.
## ⛔ The warning goes AFTER the arity check, and I had it the other way first
I wrote the call as the method's first statement, with a comment claiming that
was upstream's order. It is not.
`rb_define_module_function(rb_mObjSpace, "_id2ref", os_id2ref, 1)` (gc.c:5560)
declares a **fixed arity of 1**, so `rb_error_arity` fires in the dispatcher and
`os_id2ref` — warning and all — is never entered for a wrong argument count.
Warning first would make `ObjectSpace._id2ref` with no argument complain and
*then* raise, which MRI does not do. `objectspace_test.go` already pins that
ArgumentError, so the order is covered.
The declaration site being three thousand lines from the body is why this was
worth reading rather than assuming: the arity is not visible where the function
is written.
## warnDeprecatedGvar → warnDeprecated
The helper was already `rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, …)` in
full — the `Gvar` in its name was its first caller, not anything it does.
Renamed rather than copied, and its three existing call sites updated, because a
shadowing copy is how a method ends up with two bodies and one of them dead
(the root cause of #549's coverage failure, per the notes in
`scripts/coverage/`).
Refs #799
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 1ee9fdb commit e06c688
2 files changed
Lines changed: 33 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
276 | 282 | | |
277 | 283 | | |
278 | 284 | | |
| |||
420 | 426 | | |
421 | 427 | | |
422 | 428 | | |
423 | | - | |
| 429 | + | |
424 | 430 | | |
425 | 431 | | |
426 | 432 | | |
| |||
443 | 449 | | |
444 | 450 | | |
445 | 451 | | |
446 | | - | |
| 452 | + | |
447 | 453 | | |
448 | 454 | | |
449 | 455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
208 | 226 | | |
209 | 227 | | |
210 | 228 | | |
211 | 229 | | |
| 230 | + | |
212 | 231 | | |
213 | 232 | | |
214 | 233 | | |
| |||
0 commit comments