diff --git a/lib/rbs/prototype/rb.rb b/lib/rbs/prototype/rb.rb index 83c02c16b..040681147 100644 --- a/lib/rbs/prototype/rb.rb +++ b/lib/rbs/prototype/rb.rb @@ -15,6 +15,14 @@ def method_kind :instance end end + + def attribute_kind + if singleton + :singleton + else + :instance + end + end end attr_reader :source_decls @@ -202,7 +210,7 @@ def process(node, decls:, comments:, context:) name: name, ivar_name: nil, type: Types::Bases::Any.new(location: nil), - kind: :instance, + kind: context.attribute_kind, location: nil, comment: comments[node.first_lineno - 1], annotations: [] @@ -216,7 +224,7 @@ def process(node, decls:, comments:, context:) name: name, ivar_name: nil, type: Types::Bases::Any.new(location: nil), - kind: :instance, + kind: context.attribute_kind, location: nil, comment: comments[node.first_lineno - 1], annotations: [] @@ -230,7 +238,7 @@ def process(node, decls:, comments:, context:) name: name, ivar_name: nil, type: Types::Bases::Any.new(location: nil), - kind: :instance, + kind: context.attribute_kind, location: nil, comment: comments[node.first_lineno - 1], annotations: [] diff --git a/test/rbs/rb_prototype_test.rb b/test/rbs/rb_prototype_test.rb index f8f175dac..06ea093e0 100644 --- a/test/rbs/rb_prototype_test.rb +++ b/test/rbs/rb_prototype_test.rb @@ -250,6 +250,12 @@ class Hello attr_reader :x attr_accessor :y, :z attr_writer foo, :a, 'b' + + class << self + attr_reader :x2 + attr_accessor :y2, :z2 + attr_writer foo2, :a2, 'b2' + end end module Mod @@ -278,6 +284,16 @@ class Hello attr_writer a: untyped attr_writer b: untyped + + attr_reader self.x2: untyped + + attr_accessor self.y2: untyped + + attr_accessor self.z2: untyped + + attr_writer self.a2: untyped + + attr_writer self.b2: untyped end module Mod