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

Use “Cannot find the declaration of method” for methods defined in Ruby but not in RBS #965

Open
ParadoxV5 opened this issue Nov 20, 2023 · 0 comments

Comments

@ParadoxV5
Copy link
Contributor

ParadoxV5 commented Nov 20, 2023

This helps with using Steep as an LSP by differentiating no-RBS methods from actually nonexistent methods.


ruby.rb:

class A
  # control
  module B
  end
  class C
  end
  
  # subjects
  def instance_meth
    0
  end
  new.instance_meth
  def self.class_meth
    0
  end
  class_meth

  # control
  nonexistent_method
end

rbs.rbs:

class A
end

steep check:

# Type checking files:

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

ruby.rb:3:9: [warning] Cannot find the declaration of module: `B`
│ Diagnostic ID: Ruby::UnknownConstant
│
└   module B
           ~

ruby.rb:5:8: [warning] Cannot find the declaration of class: `C`
│ Diagnostic ID: Ruby::UnknownConstant
│
└   class C
          ~

ruby.rb:12:6: [error] Type `::A` does not have method `instance_meth`
│ Diagnostic ID: Ruby::NoMethod
│
└   new.instance_meth
        ~~~~~~~~~~~~~

ruby.rb:16:2: [error] Type `singleton(::A)` does not have method `class_meth`
│ Diagnostic ID: Ruby::NoMethod
│
└   class_meth
    ~~~~~~~~~~

ruby.rb:19:2: [error] Type `singleton(::A)` does not have method `nonexistent_method`
│ Diagnostic ID: Ruby::NoMethod
│
└   nonexistent_method
    ~~~~~~~~~~~~~~~~~~

Detected 5 problems from 1 file

Preferred:

# Type checking files:

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

ruby.rb:3:9: [warning] Cannot find the declaration of module: `B`
│ Diagnostic ID: Ruby::UnknownConstant
│
└   module B
           ~

ruby.rb:5:8: [warning] Cannot find the declaration of class: `C`
│ Diagnostic ID: Ruby::UnknownConstant
│
└   class C
          ~

ruby.rb:9:6: [warning] Cannot find the declaration of method: `instance_meth`
│ Diagnostic ID: Ruby::UnknownMethod
│
└   def instance_meth
        ~~~~~~~~~~~~~

ruby.rb:13:6: [warning] Cannot find the declaration of method: `self.class_meth`
│ Diagnostic ID: Ruby::UnknownMethod
│
└   def self.class_meth
        ~~~~~~~~~~~~~~~

ruby.rb:19:2: [error] Type `singleton(::A)` does not have method `nonexistent_method`
│ Diagnostic ID: Ruby::NoMethod
│
└   nonexistent_method
    ~~~~~~~~~~~~~~~~~~

Detected 5 problems 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