soutaro / steep

Static type checker for Ruby
MIT License
1.34k stars 88 forks source link

Ruby::MethodDefinitionMissing with attr_reader #1036

Open lloeki opened 5 months ago

lloeki commented 5 months ago

Expected result:

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 commented 5 months ago

Attempted a fix in https://github.com/soutaro/steep/pull/1037, probably not a very good one.

lloeki commented 1 month ago

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.