steep icon indicating copy to clipboard operation
steep copied to clipboard

Steep does not support inverting a boolish value

Open tk0miya opened this issue 2 years ago • 2 comments

I noticed Steep emit a warning for the code inverting a boolish value. This is bad result.

# app.rbs
module Kernel
  def hello?: () -> boolish
end
# app.rb
p :hello if !hello?
$ bundle exec steep check
# Type checking files:

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

app/app.rb:1:12: [error] Type `top` does not have method `!`
│ Diagnostic ID: Ruby::NoMethod
│
└ p :hello if !hello?
              ~

Detected 1 problem from 1 file

tk0miya avatar Oct 24 '23 15:10 tk0miya

Should boolish be untyped instead?

def my_method: (boolish) -> boolish
# in = contravariant ^       ^ out = covariant

ParadoxV5 avatar Oct 24 '23 18:10 ParadoxV5

I feel changing boolish as an alias for untyped is not a good idea. Because the main usage of the boolish type is a condition clause. No methods except ! should not be allowed. Therefore it's better to keep it as an alias for top to me.

I agree that top and boolish are not the same. So it would be better to add another top-like type for boolish. But we need to work hard to do that...

tk0miya avatar Oct 25 '23 18:10 tk0miya