Demo (lack of) type narrowing.
-
Clone this repo.
-
Install dependencies:
bundle install
-
Check types with Steep:
bundle exec steep check rbs_steep_demo.rb
-
Note the following error is reported:
rbs_steep_demo.rb:12:18: [error] Type `(::Integer | nil)` does not have method `+` │ Diagnostic ID: Ruby::NoMethod │ └ @maybe_number + 1 ~ Detected 1 problem from 1 file
-
Consider that the early return on
rbs_steep_demo.rb#L10
(return if @maybe_number.nil?
) should narrow the type of@maybe_number
toInteger
, and thatInteger
has a method+
.