Skip to content

Commit

Permalink
stdlib: Make the block arguments of Kernel#proc untyped
Browse files Browse the repository at this point in the history
This changes the block argument of `Kernel#proc` to UntypedFunction.
Then the arguments of the block become untyped instead of nil.

It allows users to override the type via comment annotation.

For example:

```
proc do |a, b, c|
  # @type var a: String
  # @type var b: Integer
  # @type var c: Symbol
end
```

I found this problem on the Steep repo.
https://github.com/soutaro/steep/blob/v1.8.0/lib/steep.rb#L169-L176
  • Loading branch information
tk0miya committed Sep 30, 2024
1 parent c255458 commit 14e92e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/kernel.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ module Kernel : BasicObject
# -->
# Equivalent to Proc.new.
#
def self?.proc: () { () -> untyped } -> Proc
def self?.proc: () { (?) -> untyped } -> Proc

# <!--
# rdoc-file=proc.c
Expand Down
5 changes: 5 additions & 0 deletions test/stdlib/Kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def test_autoload?
end
end

def test_proc
assert_send_type "() { () -> untyped } -> Proc", Kernel, :proc do end
assert_send_type "() { () -> untyped } -> Proc", Kernel, :proc do |a, b| end
end

def test_rand
assert_send_type "() -> Float", Kernel, :rand
assert_send_type "(0) -> Float", Kernel, :rand, 0
Expand Down

0 comments on commit 14e92e1

Please sign in to comment.