Skip to content

Commit

Permalink
Fix method type
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Dec 19, 2024
1 parent 41ec245 commit bc6b2b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/range.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,10 @@ class Range[out Elem] < Object
# ('a'..'e').step { p _1 }
# # Default step 1; prints: a, b, c, d, e
#
def step: (?Numeric | int n) -> Enumerator[Elem, self]
| (?Numeric | int n) { (Elem element) -> void } -> self
def step: (?Numeric | int) -> Enumerator[Elem, self]
| (?Numeric | int) { (Elem element) -> void } -> self
| (untyped) -> Enumerator[Elem, self]
| (untyped) { (Elem element) -> void } -> self

# <!--
# rdoc-file=range.c
Expand Down
7 changes: 7 additions & 0 deletions test/typecheck/range_step/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
D = Steep::Diagnostic

target :test do
signature "."
check "."
configure_code_diagnostics(D::Ruby.all_error)
end
10 changes: 10 additions & 0 deletions test/typecheck/range_step/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# These are valid because step is a number.

(1...3).step(1) { }
("A".."C").step(1) { }

# This works because "A" + "" is valid.
("A".."C").step("") { }

# This doesn't work but the type checker cannot detect it.
("A".."C").step(Exception.new) { }

0 comments on commit bc6b2b0

Please sign in to comment.