Skip to content

Commit

Permalink
Merge pull request #505 from pocke/Support-singleton-attr-by-prototyp…
Browse files Browse the repository at this point in the history
…e-rb

Support singleton attr by prototype rb
  • Loading branch information
soutaro committed Dec 6, 2020
2 parents b5ee717 + 8871f6d commit b0b10d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/rbs/prototype/rb.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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: []
Expand All @@ -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: []
Expand All @@ -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: []
Expand Down
16 changes: 16 additions & 0 deletions test/rbs/rb_prototype_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b0b10d9

Please sign in to comment.