Repository navigation
prelude: Enumerable#to_set warns on arguments, in the six places MRI does and no others - #945
Merged
Merged
Conversation
…does and no others #909: MRI 4.0 warns when Enumerable#to_set is passed arguments and rbgo was silent -- 206 bytes on stderr against 0. Measured through cmd/oracle against MRI 4.0.7, and THREE of the six cases are not what "with arguments warns" would lead anyone to write: [1,2].to_set silent [1,2].to_set(Set) warns <- even though Set IS the default value [1,2].to_set(MySet) warns [1,2].to_set { … } SILENT <- a block alone is not "arguments" (1..3).to_set silent (1..3).to_set(Set) warns Set[1,2].to_set(Set) SILENT <- Set#to_set does not warn at all under Warning[:deprecated] = false STILL WARNS Set is a C core class in 4.0, so there is no set.rb to read: the behaviour is the spec, and the oracle is how it was obtained. ## Arity, not value `def to_set(klass = Set, *args)` cannot express rows 1 and 2: inside the method `to_set` and `to_set(Set)` are identical -- klass == Set, args empty, both times. So the signature is `*args` and the test is `args.empty?`. And the warning is a plain `warn`, NOT the :deprecated category, because MRI still emits it under `Warning[:deprecated] = false`. Routing it through the category would silence something MRI does not silence. ## Range#to_set needed two changes, neither of which alters what it returns 1. `*args` instead of `klass = Set`. The C it quotes in its own comment forwards argc/argv VERBATIM (`rb_call_super(argc, argv)`) and a default parameter does not: a bare `range.to_set` was reaching Enumerable#to_set carrying an explicit Set. Harmless while that method ignored the difference, a false warning the moment it stopped. 2. It warns itself and calls a warning-free core instead of `super`, so there is exactly one warning and its uplevel is computed from a known depth. ⚠ So the call shape no longer mirrors rb_call_super while the RESULT still does. The C can forward blindly because both to_set are C and add no Ruby frame; a prelude written in Ruby cannot. ## ⛔ The line number, and a test that could not see it With the warning at `uplevel: 1` the prefix mixed the CALLER'S PATH with the PRELUDE'S LINE: MRI probe.rb:15 probe.rb:16 rbgo probe.rb:214 probe.rb:1208 <- in a 16-line file A real file at an impossible line. Same shape as a line number that belongs to the parser rather than the document. ⛔ And the first version of the test asserted `msg.include?("prelude") == false` and PASSED under that mutation -- because the message never says "prelude", it says the user's filename with the prelude's line. A test written for a property it cannot see is worse than no test. The assertion is now on the NUMBER, taken from `__LINE__` at the call site, and the mutation turns it red on BOTH paths. ## Checks - `cmd/oracle` with MRI 4.0.7 and this build: 2 engines AGREED, byte for byte, stdout AND stderr (1230 bytes, all six warnings on the caller's lines). - `gotest` over the new test plus TestEmbeddedPreludeMatchesSource (the prelude drift gate), TestASetSubclassReportsItsOwnClass and the three Set suites: all green, 2.685s. - `gofmt -l .` silent; the frozen prelude regenerated with cmd/freeze-prelude. ⚠ Not verified locally: whether the new warning changes any ruby/spec file's count. core/enumerable/to_set_spec.rb should gain the example it was failing, but a spec that calls to_set with a class and asserts silence would lose one. The rubyspec-ratchet lane is the judge of that and I have not pre-empted it. Refs #909 Co-Authored-By: Claude Opus 5 <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.
prelude: Enumerable#to_set warns on arguments, in the six places MRI does and no others
#909: MRI 4.0 warns when Enumerable#to_set is passed arguments and rbgo was
silent -- 206 bytes on stderr against 0. Measured through cmd/oracle against
MRI 4.0.7, and THREE of the six cases are not what "with arguments warns" would
lead anyone to write:
[1,2].to_set silent
[1,2].to_set(Set) warns <- even though Set IS the default value
[1,2].to_set(MySet) warns
[1,2].to_set { … } SILENT <- a block alone is not "arguments"
(1..3).to_set silent
(1..3).to_set(Set) warns
Set[1,2].to_set(Set) SILENT <- Set#to_set does not warn at all
under Warning[:deprecated] = false STILL WARNS
Set is a C core class in 4.0, so there is no set.rb to read: the behaviour is
the spec, and the oracle is how it was obtained.
Arity, not value
def to_set(klass = Set, *args)cannot express rows 1 and 2: inside the methodto_setandto_set(Set)are identical -- klass == Set, args empty, bothtimes. So the signature is
*argsand the test isargs.empty?.And the warning is a plain
warn, NOT the :deprecated category, because MRIstill emits it under
Warning[:deprecated] = false. Routing it through thecategory would silence something MRI does not silence.
Range#to_set needed two changes, neither of which alters what it returns
*argsinstead ofklass = Set. The C it quotes in its own comment forwardsargc/argv VERBATIM (
rb_call_super(argc, argv)) and a default parameter doesnot: a bare
range.to_setwas reaching Enumerable#to_set carrying an explicitSet. Harmless while that method ignored the difference, a false warning the
moment it stopped.
super, so there isexactly one warning and its uplevel is computed from a known depth.
⚠ So the call shape no longer mirrors rb_call_super while the RESULT still does.
The C can forward blindly because both to_set are C and add no Ruby frame; a
prelude written in Ruby cannot.
⛔ The line number, and a test that could not see it
With the warning at
uplevel: 1the prefix mixed the CALLER'S PATH with thePRELUDE'S LINE:
MRI probe.rb:15 probe.rb:16
rbgo probe.rb:214 probe.rb:1208 <- in a 16-line file
A real file at an impossible line. Same shape as a line number that belongs to
the parser rather than the document.
⛔ And the first version of the test asserted
msg.include?("prelude") == falseand PASSED under that mutation -- because the message never says "prelude", it
says the user's filename with the prelude's line. A test written for a property
it cannot see is worse than no test. The assertion is now on the NUMBER, taken
from
__LINE__at the call site, and the mutation turns it red on BOTH paths.Checks
cmd/oraclewith MRI 4.0.7 and this build: 2 engines AGREED, byte for byte,stdout AND stderr (1230 bytes, all six warnings on the caller's lines).
gotestover the new test plus TestEmbeddedPreludeMatchesSource (the preludedrift gate), TestASetSubclassReportsItsOwnClass and the three Set suites: all
green, 2.685s.
gofmt -l .silent; the frozen prelude regenerated with cmd/freeze-prelude.⚠ Not verified locally: whether the new warning changes any ruby/spec file's
count. core/enumerable/to_set_spec.rb should gain the example it was failing,
but a spec that calls to_set with a class and asserts silence would lose one.
The rubyspec-ratchet lane is the judge of that and I have not pre-empted it.
Refs #909
Co-Authored-By: Claude Opus 5 noreply@anthropic.com