lib/rbs/definition_builder.rb in rbs-0.19.0 vs lib/rbs/definition_builder.rb in rbs-0.20.0
- old
+ new
@@ -556,11 +556,11 @@
mixin_member: interface_methods[method_name][1],
entries: array.map(&:first)
)
end
- unless array.all? {|pair| pair[1] == :public}
+ unless array.all? {|pair| pair[1] == :public }
raise InconsistentMethodVisibilityError.new(
type_name: type_name,
method_name: method_name,
kind: :instance,
member_pairs: array
@@ -656,72 +656,19 @@
entry.decls.each do |d|
each_member_with_accessibility(d.decl.members) do |member, accessibility|
case member
when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
- name = member.name
- type = member.type
-
- ivar_name = case member.ivar_name
- when false
- nil
- else
- member.ivar_name || :"@#{member.name}"
- end
-
- if member.is_a?(AST::Members::AttrReader) || member.is_a?(AST::Members::AttrAccessor)
- definition.methods[name] = Definition::Method.new(
- super_method: nil,
- defs: [
- Definition::Method::TypeDef.new(
- type: MethodType.new(
- type_params: [],
- type: Types::Function.empty(type),
- block: nil,
- location: nil
- ),
- member: member,
- defined_in: type_name,
- implemented_in: type_name
- )
- ],
- accessibility: accessibility,
- alias_of: nil
+ if member.kind == :instance
+ build_attribute(
+ type_name: type_name,
+ definition: definition,
+ member: member,
+ accessibility: accessibility
)
end
- if member.is_a?(AST::Members::AttrWriter) || member.is_a?(AST::Members::AttrAccessor)
- definition.methods[:"#{name}="] = Definition::Method.new(
- super_method: nil,
- defs: [
- Definition::Method::TypeDef.new(
- type: MethodType.new(
- type_params: [],
- type: Types::Function.empty(type).update(
- required_positionals: [Types::Function::Param.new(name: name, type: type)]
- ),
- block: nil,
- location: nil
- ),
- member: member,
- defined_in: type_name,
- implemented_in: type_name
- ),
- ],
- accessibility: accessibility,
- alias_of: nil
- )
- end
-
- if ivar_name
- definition.instance_variables[ivar_name] = Definition::Variable.new(
- parent_variable: nil,
- type: type,
- declared_in: type_name
- )
- end
-
when AST::Members::InstanceVariable
definition.instance_variables[member.name] = Definition::Variable.new(
parent_variable: nil,
type: member.type,
declared_in: type_name
@@ -980,12 +927,20 @@
)
end
end
entry.decls.each do |d|
- each_member_with_accessibility(d.decl.members) do |member, _|
+ each_member_with_accessibility(d.decl.members) do |member, accessibility|
case member
+ when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
+ if member.kind == :singleton
+ build_attribute(type_name: type_name,
+ definition: definition,
+ member: member,
+ accessibility: accessibility)
+ end
+
when AST::Members::ClassInstanceVariable
definition.instance_variables[member.name] = Definition::Variable.new(
parent_variable: nil,
type: member.type,
declared_in: type_name
@@ -999,9 +954,73 @@
)
end
end
end
end
+ end
+ end
+
+ def build_attribute(type_name:, definition:, member:, accessibility:)
+ name = member.name
+ type = member.type
+
+ ivar_name = case member.ivar_name
+ when false
+ nil
+ else
+ member.ivar_name || :"@#{member.name}"
+ end
+
+ if member.is_a?(AST::Members::AttrReader) || member.is_a?(AST::Members::AttrAccessor)
+ definition.methods[name] = Definition::Method.new(
+ super_method: nil,
+ defs: [
+ Definition::Method::TypeDef.new(
+ type: MethodType.new(
+ type_params: [],
+ type: Types::Function.empty(type),
+ block: nil,
+ location: nil
+ ),
+ member: member,
+ defined_in: type_name,
+ implemented_in: type_name
+ )
+ ],
+ accessibility: accessibility,
+ alias_of: nil
+ )
+ end
+
+ if member.is_a?(AST::Members::AttrWriter) || member.is_a?(AST::Members::AttrAccessor)
+ definition.methods[:"#{name}="] = Definition::Method.new(
+ super_method: nil,
+ defs: [
+ Definition::Method::TypeDef.new(
+ type: MethodType.new(
+ type_params: [],
+ type: Types::Function.empty(type).update(
+ required_positionals: [Types::Function::Param.new(name: name, type: type)]
+ ),
+ block: nil,
+ location: nil
+ ),
+ member: member,
+ defined_in: type_name,
+ implemented_in: type_name
+ ),
+ ],
+ accessibility: accessibility,
+ alias_of: nil
+ )
+ end
+
+ if ivar_name
+ definition.instance_variables[ivar_name] = Definition::Variable.new(
+ parent_variable: nil,
+ type: type,
+ declared_in: type_name
+ )
end
end
def merge_definitions(type_name, pairs, entry:, self_type:, ancestors:)
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|