Repository navigation
Conversation
Add signatures for singleton methods that are defined in Ruby 4.0 but were missing from core/: - Hash.ruby2_keywords_hash, Hash.ruby2_keywords_hash? - Kernel.set_trace_func, Kernel.trap - Process.last_status, Process.setpgrp - Process::Status.wait - Process::Sys.getegid
zonuexe
force-pushed
the
method-drift-test
branch
from
October 11, 2026 08:02
2340b92 to
bf99934
Compare
ksss
reviewed
Oct 11, 2026
|
|
||
| * `Numeric#+` and `#-` are declared on `Numeric` so that code typed as `Numeric` can add and subtract, although only its subclasses define them. | ||
| * `Struct.members` and `.keyword_init?` are declared on `Struct`, although Ruby defines them only on the classes that `Struct.new` creates. | ||
| * A method that Ruby undefines in a subclass is declared with the `bot` return type, so that calling it is a type error. For example, `Complex#<` is declared as `def <: (Numeric) -> bot`, because `Complex` undefines the `<` inherited from `Comparable`. |
Collaborator
There was a problem hiding this comment.
Calling a method that returns bot does not mean a type error.
For example, Kernel#raise is a type safe method.
ksss
reviewed
Oct 11, 2026
ksss
left a comment
Collaborator
There was a problem hiding this comment.
Since adding type definitions and adding test features are separate proposals, it would be helpful if you could split them into separate PRs.
Collaborator
|
Ah, so this was the stack from #3218. My apologies. The PR had already been split. |
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.
Stacked on #3218. Only the last 3 commits are new; the test fails without the singleton methods that #3218 adds. I will rebase this onto master after #3218 is merged.
test/stdlib/method_drift_test.rbworks likeConstantDriftTest, but checks methods instead of constants. For a fixed list of platform-invariant core classes (Integer,String,Hash,Binding, ...), it checks both directions:singleton_methods(false)withDefinitionBuilder#build_singleton, andpublic_instance_methods(false)+protected_instance_methods(false)with#build_instance. Only methods implemented in C or<internal:...>count, so methods added by libraries such asppandjson/addare ignored. A method declared on an ancestor counts as declared.botreturn type are skipped, because RBS uses it for methods that Ruby undefines (e.g.Complex#<).To check that the test works, I replaced
core/hash.rbswith the version from master. The test then reported::Hash.ruby2_keywords_hashand::Hash.ruby2_keywords_hash?.Exceptions in
MethodDriftTest::SKIPNumeric#+,#-Numericso that code typed asNumericcan add and subtract (aaf7623). Only the subclasses define themStruct.members,.keyword_init?Struct.newcreatesEnumerable#to_enum,#enum_forKernel. These declarations are no more precise thanKernel#enum_for, so they may be removedMethod#boxRuby::Boxin Ruby 4.0, which has no signature yetThe first two rows are now documented in a new Q&A item in
docs/CONTRIBUTING.md, "Why does RBS declare methods that Ruby does not define on that class?", together with thebotconvention.Other changes
Binding#irb: (?show_code: boolish) -> void. It is defined in<internal:prelude>and was not declared anywhere. It has no test, because calling it starts an IRB session.Ruby development builds
On a development build of Ruby (
RUBY_PATCHLEVEL < 0, i.e. ruby-head), the test reports drift withnotifyinstead of failing. New methods appear on head before they can be declared in RBS: the first CI run of this PR found 22 on Ruby 4.1.0dev, such asString#bit_getandRange#clamp. On Ruby 4.0 the test fails as usual. Whether to also run it as a failing nightly job on head can be decided separately.