Repository navigation
Commit 06d605e
The separator globals accept a String subclass, as MRI's T_STRING test does (#897)
Closes #884. `language/predefined_spec.rb` goes 143 → 145, errors 6 → 4.
## How this was found
By counting, not by reading the backlog. #799's table credits #886 with 4
examples of `language/predefined_spec.rb`; running the file against current
main says otherwise:
RBGO_RESULT pass=143 fail=16 error=6
RBGO_DETAIL error TypeError Predefined global $/ | makes a new frozen String from the assigned String value of $/ must be String
RBGO_DETAIL error TypeError Predefined global $-0 | makes a new frozen String from the assigned String value of $-0 must be String
#886 closed TWO of the four, not four, and said so at the time — the String
subclass example was named in its body as a known limitation and filed as #884.
The tally in the issue kept the old number, and a pass count cannot tell the
difference.
## The cause is one assertion, and it was in five places
if _, ok := v.(*object.String); !ok { raise("TypeError", ...) }
An exact-type assertion. MRI's are RB_TYPE_P(val, T_STRING) in rb_str_setter
and rb_check_string_type in rb_fs_check, and both are TRUE for a subclass. rbgo
represents an instance of `Class.new(String)` as an RObject wrapping a String,
so the assertion missed every one of them. stringTyped is that test.
## The five globals do not do the same thing afterwards
Measured on MRI 4.0.7, assigning the same `Class.new(String).new("abc")` with
an @ivar:
| global | setter | result |
|---|---|---|
| `$/`, `$-0` | deprecated_rs_setter | a frozen BARE String — class String, no ivar |
| `$,`, `$\` | rb_str_setter | the object as handed over, unfrozen |
| `$;` | rb_fs_setter | the object as handed over, unfrozen |
A fix that froze and copied everywhere would pass the two spec examples and
silently rewrite the other three. The test table asserts each separately.
## $; was wrong differently, and worse
It did not refuse the subclass — it fell through to #to_str, which a String
subclass answers. The assignment SUCCEEDED and quietly replaced the object with
a plain String. The others at least raised.
## frozenBareString's comment had outlived its reason
It said only the ivar half of BARE_STRING_P was tested, because a subclass
"never reaches this function at all". That was true while checkStrGvar rejected
it. Now it does reach it, and without the class test the subclass instance
would be returned AS IS — ivar and all. The function takes the original value
as well as the String inside it, and tests both halves.
## Measured
rubydiff against MRI 4.0.7 on all five globals plus the non-String refusals:
AGREE.
specdelta, provenanced, over language, core/string, core/io and core/kernel:
442 files, control 9666, treatment 9668, +2, 1 file moved, 0 regressed.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent f20a1ac commit 06d605e
2 files changed
Lines changed: 159 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
484 | | - | |
| 484 | + | |
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
488 | 491 | | |
489 | 492 | | |
490 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
491 | 516 | | |
492 | 517 | | |
493 | 518 | | |
| |||
514 | 539 | | |
515 | 540 | | |
516 | 541 | | |
517 | | - | |
| 542 | + | |
518 | 543 | | |
519 | 544 | | |
520 | 545 | | |
521 | 546 | | |
522 | 547 | | |
523 | 548 | | |
524 | 549 | | |
525 | | - | |
| 550 | + | |
526 | 551 | | |
527 | 552 | | |
528 | 553 | | |
| |||
536 | 561 | | |
537 | 562 | | |
538 | 563 | | |
539 | | - | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
540 | 568 | | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
551 | 582 | | |
552 | 583 | | |
553 | 584 | | |
| |||
563 | 594 | | |
564 | 595 | | |
565 | 596 | | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
573 | 612 | | |
| 613 | + | |
574 | 614 | | |
575 | | - | |
576 | 615 | | |
577 | 616 | | |
578 | 617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
0 commit comments