steep icon indicating copy to clipboard operation
steep copied to clipboard

The type is assumed to be optional even so there is if check

Open yui-knk opened this issue 1 year ago • 0 comments

Abstract

The type is assumed to be optional even so there is if check before method call.

Steep version

  • steep (1.5.3)

How to reproduce

  1. Check out https://github.com/yui-knk/steep_playground/commit/1a9d3674069ab483a90b6ebb41f5d8ef623b9c43
  2. Run bundle install & bundle exec steep check
% bundle exec steep check
# Type checking files:

..................................................................................F...

lib/steep_playground/safe_operator/main.rb:8:26: [error] Type `(::SteepPlayground::SafeOperator::Klass | nil)` does not have method `num`
│ Diagnostic ID: Ruby::NoMethod
│
└           sub(klass.right.num)
                            ~~~

lib/steep_playground/safe_operator/main.rb:18:26: [error] Type `(::SteepPlayground::SafeOperator::Klass | nil)` does not have method `left`
│ Diagnostic ID: Ruby::NoMethod
│
└           sub(klass.right.left.num)
                            ~~~~

Expectation

In both cases, type of #sub argument is assumed to ::SteepPlayground::SafeOperator::Klass because there is if klass.right and if klass.right&.left before sub method call.

yui-knk avatar Aug 19 '23 06:08 yui-knk