castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.87k stars 154 forks source link

Exception type-checking method with super call #669

Closed apiology closed 12 months ago

apiology commented 1 year ago

How to reproduce

Run solargraph typecheck on this file:

class MySuperClass
  # @return [Integer]
  def my_method
    123
  end
end

class SolargraphRepro < MySuperClass
  # @return [Integer]
  def my_method
    456 + super
  end
end

Expected result

No crash

Observed result

bundler: failed to load command: solargraph (/Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bin/solargraph)
/Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:202:in `super_pins': undefined method `scope' for #<Solargraph::Pin::ProxyType `` at nil> (NoMethodError)

          pins = api_map.get_method_stack(name_pin.namespace, name_pin.name, scope: name_pin.scope)
                                                                                            ^^^^^^
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/z_super.rb:25:in `resolve'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain.rb:71:in `define'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain.rb:83:in `infer'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:69:in `block (3 levels) in inferred_pins'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:63:in `each'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:63:in `each_with_index'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:63:in `block (2 levels) in inferred_pins'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:59:in `each'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:59:in `block in inferred_pins'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:54:in `map'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:54:in `inferred_pins'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain/call.rb:43:in `resolve'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain.rb:71:in `define'
    from /Users/broz/src/solargraph/lib/solargraph/source/chain.rb:83:in `infer'
    from /Users/broz/src/solargraph/lib/solargraph/pin/method.rb:313:in `block in infer_from_return_nodes'
    from /Users/broz/src/solargraph/lib/solargraph/pin/method.rb:301:in `each'
    from /Users/broz/src/solargraph/lib/solargraph/pin/method.rb:301:in `infer_from_return_nodes'
    from /Users/broz/src/solargraph/lib/solargraph/pin/method.rb:153:in `probe'
    from /Users/broz/src/solargraph/lib/solargraph/type_checker.rb:102:in `method_return_type_problems_for'
    from /Users/broz/src/solargraph/lib/solargraph/type_checker.rb:80:in `block in method_tag_problems'
    from /Users/broz/src/solargraph/lib/solargraph/type_checker.rb:79:in `each'
    from /Users/broz/src/solargraph/lib/solargraph/type_checker.rb:79:in `method_tag_problems'
    from /Users/broz/src/solargraph/lib/solargraph/type_checker.rb:44:in `problems'
    from /Users/broz/src/solargraph/lib/solargraph/shell.rb:156:in `block in typecheck'
    from /Users/broz/src/solargraph/lib/solargraph/shell.rb:154:in `each'
    from /Users/broz/src/solargraph/lib/solargraph/shell.rb:154:in `typecheck'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
    from /Users/broz/src/solargraph/bin/solargraph:5:in `<top (required)>'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bin/solargraph:25:in `load'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bin/solargraph:25:in `<top (required)>'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `load'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:23:in `run'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:492:in `exec'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:34:in `dispatch'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:28:in `start'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/exe/bundle:45:in `block in <top (required)>'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /Users/broz/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/exe/bundle:33:in `<top (required)>'
    from /Users/broz/.rbenv/versions/3.2.2/bin/bundle:25:in `load'
    from /Users/broz/.rbenv/versions/3.2.2/bin/bundle:25:in `<main>'

Compilation exited abnormally with code 1 at Fri Jun 16 18:33:21