Correct core/stdlib signatures to match Ruby 4.0#2967
Merged
Conversation
Update several signatures that were inaccurate against the Ruby 4.0
implementation:
- `IO#pathconf`: add the method (`(Integer) -> Integer?`).
- `Digest::Instance#finish`: return `String`, not `self`.
- `Digest::Class.{digest,hexdigest,bubblebabble,file,base64digest}`:
accept the trailing `*args` passed to the constructor.
- `Etc.sysconf` / `Etc.systmpdir`: return types are nilable.
- `Etc::Group.each` / `Etc::Passwd.each`: add block / Enumerator overloads.
- `Etc::Passwd`: add the `age`, `comment`, and `quota` members.
- `StringIO`: non-block `self.open` overload; `fcntl` always raises
(`bot`); `fsync` returns `0`; `internal_encoding` returns `nil`;
`external_encoding` is nilable; add `pread` and `write_nonblock`;
`read_nonblock` takes `exception:` and is nilable; `sysread` `outbuf`
is optional; `ungetc` also accepts an `Integer`; add `set_encoding_by_bom`.
ksss
approved these changes
May 23, 2026
ksss
reviewed
May 28, 2026
| # is properly padded with '=' and contains no line feeds. | ||
| # | ||
| def self.base64digest: (string str) -> String | ||
| def self.base64digest: (string str, *untyped args) -> String |
Collaborator
There was a problem hiding this comment.
I have already merged it, but I believe there is an issue with these changes.
For example, the following code will cause an ArgumentError in actual behavior, but it passes the type check.
Digest::SHA256.base64digest("aaa", :bbb) #=> ArgumentErrorWhile these methods are indeed delegated to the constructor, since it is not possible to describe this delegation in RBS, I believe we should add appropriate overloads in each class.
I will fix it soon.
We will address the issue that the existing test cases failed to detect the problem as a problem with the test harness.
ksss
added a commit
that referenced
this pull request
May 28, 2026
The original definition allows for flexible behavior in subclasses,
but it can also lead to overlooking issues that should be discovered.
If we want to increase the number of arguments in a subclass,
we should write an overload in that class.
```
Digest::SHA256.base64digest("aaa", :bbb) #=> ArgumentError
```
ref: #2967
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.
Summary
Several core/stdlib signatures were inaccurate against the Ruby 4.0 implementation. This corrects them.
IO#pathconf(Integer name) -> Integer?Digest::Instance#finishString, notselfDigest::Class.digest/.hexdigest/.bubblebabble*args(passed through to the constructor)Digest::Class.file/.base64digest*argsEtc.sysconf-> Integer?Etc.systmpdir-> String?Etc::Group.each/Etc::Passwd.eachEnumeratoroverloads instead of-> untypedEtc::Passwdage,comment, andquotamembers (with their setters)StringIO.open(?String, ?String?) -> StringIOStringIO#fcntlNotImplementedError— returnbotStringIO#fsync0—-> Integer(notInteger?)StringIO#internal_encodingnilStringIO#external_encoding-> Encoding?StringIO#preadStringIO#read_nonblockexception:; return type is nilableStringIO#write_nonblockStringIO#sysreadoutbufis optionalStringIO#ungetcIntegerStringIO#set_encoding_by_bomNotes
Monitor#wait_for_cond/MonitorMixin::ConditionVariable#wait(-> bool) are intentionally excluded here — they are covered by Replace deterministicuntypedreturn types with concrete types #2966.rbs annotateoutput (confirm_annotation).Test plan
bundle exec rbs validatebundle exec rbs -r digest -r etc -r stringio validatebundle exec rubocop core/io.rbs stdlib/digest/0/digest.rbs stdlib/etc/0/etc.rbs stdlib/stringio/0/stringio.rbs