Skip to content

Commit

Permalink
Merge pull request #1787 from ksss/attr-location
Browse files Browse the repository at this point in the history
Add location for attribute
  • Loading branch information
soutaro authored Apr 6, 2024
2 parents 7df8409 + 570c58a commit 00bad8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rbs/definition_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,15 @@ def define_method(methods, definition, method, subst, defined_in:, implemented_i
]
),
block: nil,
location: nil
location: original.location
)
else
# getter
MethodType.new(
type_params: [],
type: Types::Function.empty(attr_type),
block: nil,
location: nil
location: original.location
)
end

Expand Down
8 changes: 8 additions & 0 deletions test/rbs/definition_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,13 +1088,17 @@ class Hello
assert_instance_of Definition, definition

assert_method_definition definition.methods[:instance_reader], ["() -> ::String"]
assert_equal definition.methods[:instance_reader].method_types.first.location.source, "attr_reader instance_reader: String"
assert_ivar_definition definition.instance_variables[:@instance_reader], "::String"

assert_method_definition definition.methods[:instance_writer=], ["(::Integer instance_writer) -> ::Integer"]
assert_equal definition.methods[:instance_writer=].method_types.first.location.source, "attr_writer instance_writer(@writer): Integer"
assert_ivar_definition definition.instance_variables[:@writer], "::Integer"

assert_method_definition definition.methods[:instance_accessor], ["() -> ::Symbol"]
assert_equal definition.methods[:instance_accessor].method_types.first.location.source, "attr_accessor instance_accessor(): Symbol"
assert_method_definition definition.methods[:instance_accessor=], ["(::Symbol instance_accessor) -> ::Symbol"]
assert_equal definition.methods[:instance_accessor=].method_types.first.location.source, "attr_accessor instance_accessor(): Symbol"
assert_nil definition.instance_variables[:@instance_accessor]
end
end
Expand All @@ -1117,13 +1121,17 @@ class Hello
assert_instance_of Definition, definition

assert_method_definition definition.methods[:reader], ["() -> ::String"]
assert_equal definition.methods[:reader].method_types.first.location.source, "attr_reader self.reader: String"
assert_ivar_definition definition.instance_variables[:@reader], "::String"

assert_method_definition definition.methods[:writer=], ["(::Integer writer) -> ::Integer"]
assert_equal definition.methods[:writer=].method_types.first.location.source, "attr_writer self.writer(@writer): Integer"
assert_ivar_definition definition.instance_variables[:@writer], "::Integer"

assert_method_definition definition.methods[:accessor], ["() -> ::Symbol"]
assert_equal definition.methods[:accessor].method_types.first.location.source, "attr_accessor self.accessor(): Symbol"
assert_method_definition definition.methods[:accessor=], ["(::Symbol accessor) -> ::Symbol"]
assert_equal definition.methods[:accessor=].method_types.first.location.source, "attr_accessor self.accessor(): Symbol"
assert_nil definition.instance_variables[:@accessor]
end
end
Expand Down

0 comments on commit 00bad8a

Please sign in to comment.