Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steep does not support inverting a boolish value #939

Open
tk0miya opened this issue Oct 24, 2023 · 2 comments
Open

Steep does not support inverting a boolish value #939

tk0miya opened this issue Oct 24, 2023 · 2 comments

Comments

@tk0miya
Copy link
Contributor

tk0miya commented Oct 24, 2023

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 added a commit to tk0miya/steep that referenced this issue Oct 24, 2023
tk0miya added a commit to tk0miya/rbs that referenced this issue Oct 24, 2023
To support inverting boolish values, adds a new interface `_Top` that
provides `!` operator.

refs: soutaro/steep#939
@ParadoxV5
Copy link
Contributor

Should boolish be untyped instead?

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

@tk0miya
Copy link
Contributor Author

tk0miya commented Oct 25, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants