Skip to content

Replace deterministic untyped return types with concrete types#2966

Open
zonuexe wants to merge 1 commit into
ruby:masterfrom
zonuexe:fix/concrete-untyped-returns
Open

Replace deterministic untyped return types with concrete types#2966
zonuexe wants to merge 1 commit into
ruby:masterfrom
zonuexe:fix/concrete-untyped-returns

Conversation

@zonuexe
Copy link
Copy Markdown
Contributor

@zonuexe zonuexe commented May 21, 2026

Summary

Several methods were typed -> untyped even though the implementation makes the return value deterministic. This replaces those with concrete types.

Ruby Method untyped Basis
StringIO#putc (Numeric | String) returns its argument
Zlib::GzipWriter#putc (Numeric | String) returns its argument
Zlib::GzipFile#sync= boolish setter returns its argument
MonitorMixin::ConditionVariable#wait_for_cond bool C implementation returns Qtrue / Qfalse
MonitorMixin::ConditionVariable#wait bool delegates to #wait_for_cond
MonitorMixin::ConditionVariable#wait_until nil body is an until loop expression
MonitorMixin::ConditionVariable#wait_while nil body is a while loop expression
ERB#run nil print self.result(b)print returns nil
ERB#initialize void constructor
ERB#def_method Symbol module_eval { eval("def …\nend") } returns the method name
ERB::DefMethod.def_erb_method Symbol delegates to ERB#def_method

Out of scope

  • ObjectSpace.internal_super_of — although the doc says it returns "Class or Module", it actually returns the internal super entry, which can be a T_ICLASS object. That is not a real Module, so untyped is the correct type (the stdlib_test for it confirms this). Left unchanged.
  • The core/class.rbs (allocate, new) and core/struct.rbs (self.new) untypedinstance proposals were left out: Class#new is special-cased by the type checker, and Struct.new(:a, :b) returns a new struct class (not an instance), so instance would be incorrect there.

Test plan

  • bundle exec rbs -r stringio -r zlib -r monitor -r erb validate
  • bundle exec rake stdlib_test
  • bundle exec rubocop on the changed files

@zonuexe zonuexe marked this pull request as draft May 21, 2026 10:58
Several methods were typed `-> untyped` even though their return value
is determined by the implementation. Give them concrete types:

- `StringIO#putc`, `Zlib::GzipWriter#putc` -> `Numeric | String` (returns the argument)
- `Zlib::GzipFile#sync=` -> `boolish` (setter returns the argument)
- `MonitorMixin::ConditionVariable#wait_for_cond` / `#wait` -> `bool`
- `MonitorMixin::ConditionVariable#wait_until` / `#wait_while` -> `nil` (loop expression)
- `ERB#run` -> `nil`, `ERB#initialize` -> `void`
- `ERB#def_method`, `ERB::DefMethod.def_erb_method` -> `Symbol`
@zonuexe zonuexe force-pushed the fix/concrete-untyped-returns branch from 0886f54 to 51d27db Compare May 21, 2026 10:59
@zonuexe zonuexe marked this pull request as ready for review May 21, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant