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

Ruby::MethodDefinitionMissing with attr_reader #1036

Open
lloeki opened this issue Jan 29, 2024 · 2 comments · May be fixed by #1037
Open

Ruby::MethodDefinitionMissing with attr_reader #1036

lloeki opened this issue Jan 29, 2024 · 2 comments · May be fixed by #1037

Comments

@lloeki
Copy link
Contributor

lloeki commented Jan 29, 2024

  • attr_reader foo: untyped in RBS defines the signature for the method #foo as would def foo: () -> untyped
  • with Steep::Diagnostic::Ruby::MethodDefinitionMissing Steep expects the method #foo from the above
  • attr_reader in Ruby defines the method #foo yet Steep can't find it, even though both .rb and .rbsuseattr_reader` semantics

Expected result:

  • attr_reader foo: untyped should be able to find attr_reader-defined methods
  • Arguably def foo: () -> untyped + @foo: untyped should also work with and find attr_reader :foo
  • Same for attr_writer and attr_accessor and #foo=

Actual result:

# foo.rb
class Foo
  attr_reader :foo
end
# foo.rbs
class Foo
  attr_reader foo: untyped
end
# Steepfile
target :lib do
  configure_code_diagnostics do |hash|
    hash[Steep::Diagnostic::Ruby::MethodDefinitionMissing] = :error
  end

  check '.'
  signature '.'
end
$ bundle exec steep check foo.rb
foo.rb:1:6: [error] Cannot find implementation of method `::Foo#foo`
│ Diagnostic ID: Ruby::MethodDefinitionMissing
│
└ class Foo
@lloeki lloeki linked a pull request Jan 29, 2024 that will close this issue
@lloeki
Copy link
Contributor Author

lloeki commented Jan 29, 2024

Attempted a fix in #1037, probably not a very good one.

@lloeki
Copy link
Contributor Author

lloeki commented May 10, 2024

Apparently the solution (as of 1.6.0) is to use @dynamic:

# foo.rb
class Foo
  # @dynamic foo
  attr_reader :foo
end

Which feels very redundant given that RBS's attr_reader already knows that.

lloeki added a commit to DataDog/graft-rb that referenced this issue Jun 4, 2024
Two main cases:

- `attr_*` needs `@dynamic`: soutaro/steep#1036
- three `define_method` because of the `RUBY_VERSION` condition
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

Successfully merging a pull request may close this issue.

1 participant