From 570c58ad59f4d06c9c91d997477df6c21eea3410 Mon Sep 17 00:00:00 2001 From: ksss Date: Fri, 5 Apr 2024 00:20:51 +0900 Subject: [PATCH] Add location for attribute --- lib/rbs/definition_builder.rb | 4 ++-- test/rbs/definition_builder_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/rbs/definition_builder.rb b/lib/rbs/definition_builder.rb index 7ee6c2c98..07a42500a 100644 --- a/lib/rbs/definition_builder.rb +++ b/lib/rbs/definition_builder.rb @@ -669,7 +669,7 @@ def define_method(methods, definition, method, subst, defined_in:, implemented_i ] ), block: nil, - location: nil + location: original.location ) else # getter @@ -677,7 +677,7 @@ def define_method(methods, definition, method, subst, defined_in:, implemented_i type_params: [], type: Types::Function.empty(attr_type), block: nil, - location: nil + location: original.location ) end diff --git a/test/rbs/definition_builder_test.rb b/test/rbs/definition_builder_test.rb index 6d3855e5c..ed7c514fb 100644 --- a/test/rbs/definition_builder_test.rb +++ b/test/rbs/definition_builder_test.rb @@ -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 @@ -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