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 cannot detect the type of the rescue => variable after they leak scope in Ruby #919

Open
ParadoxV5 opened this issue Oct 1, 2023 · 1 comment

Comments

@ParadoxV5
Copy link
Contributor

ParadoxV5 commented Oct 1, 2023

ruby.rb:

begin
  0/0
rescue StandardError => e
  # fall-through
end

p e

ruby ruby.rb:

#<ZeroDivisionError: divided by 0>

steep check with strict diagnostic:

# Type checking files:

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

ruby.rb:7:2: [warning] Cannot detect the type of the expression
│ Diagnostic ID: Ruby::FallbackAny
│
└ p e
    ~

Detected 1 problem from 1 file
@ParadoxV5 ParadoxV5 changed the title Steep thinks rescue => variable is begin block scope but it actually leaks in Ruby Steep thinks variables in rescue block are scoped, but they actually leak in Ruby Oct 1, 2023
@ParadoxV5 ParadoxV5 changed the title Steep thinks variables in rescue block are scoped, but they actually leak in Ruby Steep cannot detect the type of the rescue => variable after they leak scope in Ruby Oct 1, 2023
@ParadoxV5
Copy link
Contributor Author

begin
  0/0
rescue StandardError => e
  a = e
end

p a

check with all_error diagnostic:

# Type checking files:

....................................................................................

No type error detected. 🍵

begin
  0/0
rescue StandardError => e
  a = e
end

raise a

check with default diagnostic:

# Type checking files:

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

ruby.rb:7:0: [error] Cannot find compatible overloading of method `raise` of type `::Object`
│ Method types:
│   def raise: () -> bot
│            | (::string, ?cause: (::Exception | nil)) -> bot
│            | (::_Exception, ?(::_ToS | nil), ?(nil | ::String | ::Array[::String]), ?cause: (::Exception | nil)) -> bot
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
└ raise a
  ~~~~~~~

Detected 1 problem from 1 file

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

1 participant