8000 Inferred vs declared return type namespace mismatch · Issue #841 · castwide/solargraph · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inferred vs declared return type namespace mismatch #841

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

Closed
amake opened this issue Mar 28, 2025 · 3 comments
Closed

Inferred vs declared return type namespace mismatch #841

amake opened this issue Mar 28, 2025 · 3 comments

Comments

@amake
Copy link
Contributor
amake commented Mar 28, 2025

The following code:

module MyModule
  class Bar
    def initialize
      # empty
    end
  end

  class Baz
    # empty
  end

  class Foo1 < Bar
    class << self
      # This is an error
      #
      # @return [Foo1]
      def foo
        new
      end
    end
  end

  class Foo2 < Baz
    class << self
      # But this is not an error, and the only difference is whether the parent
      # class has an `initialize` method
      #
      # @return [Foo2]
      def foo
        new
      end
    end
  end
end

Gives the following error:

% solargraph typecheck --level typed tmp.rb
tmp.rb:17 - Declared return type MyModule::Foo1 does not match inferred type Foo1 for MyModule::Foo1.foo
1 problem found.

Changing line 17 to @return [MyModule::Foo1] resolves the issue, but it seems like that shouldn't be necessary or it should be required for line 28 (@return [Foo2]) as well.

@castwide
Copy link
Owner

This bug is being addressed in #824. I expect to include the fix in a patch release soon.

@castwide
Copy link
Owner

Fix released in 0.53.3.

@amake
Copy link
Contributor Author
amake commented Mar 30, 2025

Confirmed! Thanks!

@amake amake closed this as completed Mar 30, 2025
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
0