Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/rbs/inline/ast/members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,20 @@ def rbs
class RubyAttr < RubyBase
attr_reader :node #: Prism::CallNode
attr_reader :comments #: AnnotationParser::ParsingResult?
attr_reader :visibility #: RBS::AST::Members::visibility?
attr_reader :assertion #: Annotations::TypeAssertion?

# @rbs node: Prism::CallNode
# @rbs comments: AnnotationParser::ParsingResult?
# @rbs visibility: RBS::AST::Members::visibility?
# @rbs assertion: Annotations::TypeAssertion?
# @rbs return: void
def initialize(node, comments, assertion)
def initialize(node, comments, visibility, assertion)
super(node.location)

@node = node
@comments = comments
@visibility = visibility
@assertion = assertion
end

Expand Down Expand Up @@ -466,7 +469,7 @@ def rbs
annotations: [],
location: nil,
comment: comment,
visibility: nil
visibility: visibility
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rbs/inline/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def visit_call_node(node)
end #: AST::Annotations::TypeAssertion?
end

current_class_module_decl!.members << AST::Members::RubyAttr.new(node, comment, assertion)
current_class_module_decl!.members << AST::Members::RubyAttr.new(node, comment, current_visibility, assertion)

return
end
Expand Down
5 changes: 4 additions & 1 deletion sig/generated/rbs/inline/ast/members.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ module RBS

attr_reader comments: AnnotationParser::ParsingResult?

attr_reader visibility: RBS::AST::Members::visibility?

attr_reader assertion: Annotations::TypeAssertion?

# @rbs node: Prism::CallNode
# @rbs comments: AnnotationParser::ParsingResult?
# @rbs visibility: RBS::AST::Members::visibility?
# @rbs assertion: Annotations::TypeAssertion?
# @rbs return: void
def initialize: (Prism::CallNode node, AnnotationParser::ParsingResult? comments, Annotations::TypeAssertion? assertion) -> void
def initialize: (Prism::CallNode node, AnnotationParser::ParsingResult? comments, RBS::AST::Members::visibility? visibility, Annotations::TypeAssertion? assertion) -> void

# @rbs return Array[RBS::AST::Members::AttrReader | RBS::AST::Members::AttrWriter | RBS::AST::Members::AttrAccessor]?
def rbs: () -> Array[RBS::AST::Members::AttrReader | RBS::AST::Members::AttrWriter | RBS::AST::Members::AttrAccessor]?
Expand Down
18 changes: 18 additions & 0 deletions test/rbs/inline/writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,14 @@ def test_attributes__unannotated
output = translate(<<~RUBY)
class Hello
attr_reader :foo, :foo2, "hoge".to_sym
private attr_reader :foo3

# Attribute of bar
attr_writer :bar
private attr_writer :bar2

attr_accessor :baz
private attr_accessor :baz2
end
RUBY

Expand All @@ -379,10 +382,16 @@ class Hello

attr_reader foo2: untyped

private attr_reader foo3: untyped

# Attribute of bar
attr_writer bar: untyped

private attr_writer bar2: untyped

attr_accessor baz: untyped

private attr_accessor baz2: untyped
end
RBS
end
Expand All @@ -391,11 +400,14 @@ def test_attributes__typed
output = translate(<<~RUBY)
class Hello
attr_reader :foo, :foo2, "hoge".to_sym #: String
private attr_reader :foo3 #: String

# Attribute of bar
attr_writer :bar #: Array[Integer]
private attr_writer :bar2 #: Array[Integer]

attr_accessor :baz #: Integer |
private attr_accessor :baz2 #: Integer
end
RUBY

Expand All @@ -405,10 +417,16 @@ class Hello

attr_reader foo2: String

private attr_reader foo3: String

# Attribute of bar
attr_writer bar: Array[Integer]

private attr_writer bar2: Array[Integer]

attr_accessor baz: untyped

private attr_accessor baz2: Integer
end
RBS
end
Expand Down