lib/rbs/definition_builder.rb in rbs-0.16.0 vs lib/rbs/definition_builder.rb in rbs-0.17.0

- old
+ new

@@ -597,14 +597,19 @@ def build_one_instance(type_name) try_cache(type_name, cache: one_instance_cache) do entry = env.class_decls[type_name] + param_names = entry.type_params.each.map(&:name) self_type = Types::ClassInstance.new(name: type_name, - args: Types::Variable.build(entry.type_params.each.map(&:name)), + args: Types::Variable.build(param_names), location: nil) - ancestors = [Definition::Ancestor::Instance.new(name: type_name, args: self_type.args)] + ancestors = Definition::InstanceAncestors.new( + type_name: type_name, + params: param_names, + ancestors: [Definition::Ancestor::Instance.new(name: type_name, args: self_type.args)] + ) Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition| method_definition_members(type_name, entry, kind: :instance).each do |method_name, array| visibility, method_def, primary_member, overload_members = array @@ -616,17 +621,19 @@ m = if method_def Definition::Method.new( super_method: nil, accessibility: visibility, - defs: method_def.defs.map {|defn| defn.update(implemented_in: type_name) } + defs: method_def.defs.map {|defn| defn.update(implemented_in: type_name) }, + alias_of: nil ) else Definition::Method.new( super_method: nil, accessibility: visibility, - defs: [] + defs: [], + alias_of: nil ) end definition.methods[method_name] = members.inject(m) do |original, member| defs = member.types.map do |method_type| @@ -639,11 +646,12 @@ end Definition::Method.new( super_method: nil, defs: defs + original.defs, - accessibility: original.accessibility + accessibility: original.accessibility, + alias_of: nil ) end end entry.decls.each do |d| @@ -674,11 +682,12 @@ member: member, defined_in: type_name, implemented_in: type_name ) ], - accessibility: accessibility + 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( @@ -696,11 +705,12 @@ member: member, defined_in: type_name, implemented_in: type_name ), ], - accessibility: accessibility + accessibility: accessibility, + alias_of: nil ) end if ivar_name definition.instance_variables[ivar_name] = Definition::Variable.new( @@ -745,11 +755,19 @@ methods: definition.methods, name: member.new_name, location: member.location ) - definition.methods[member.new_name] = definition.methods[member.old_name] + original_method = definition.methods[member.old_name] + + definition.methods[member.new_name] = Definition::Method.new( + super_method: original_method.super_method, + defs: original_method.defs, + accessibility: original_method.accessibility, + alias_of: original_method, + annotations: original_method.annotations + ) end end end end @@ -836,11 +854,14 @@ def build_one_singleton(type_name) try_cache(type_name, cache: one_singleton_cache) do entry = env.class_decls[type_name] self_type = Types::ClassSingleton.new(name: type_name, location: nil) - ancestors = [Definition::Ancestor::Singleton.new(name: type_name)] + ancestors = Definition::SingletonAncestors.new( + type_name: type_name, + ancestors: [Definition::Ancestor::Singleton.new(name: type_name)] + ) Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition| method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array| visibility, method_def, primary_member, overload_members = array @@ -853,11 +874,12 @@ m = Definition::Method.new( super_method: nil, defs: method_def&.yield_self do |method_def| method_def.defs.map {|defn| defn.update(implemented_in: type_name) } end || [], - accessibility: visibility + accessibility: visibility, + alias_of: nil ) definition.methods[method_name] = members.inject(m) do |original, new| defs = new.types.map do |type| Definition::Method::TypeDef.new( type: type, @@ -867,11 +889,12 @@ ) end Definition::Method.new( super_method: nil, defs: defs + original.defs, - accessibility: original.accessibility + accessibility: original.accessibility, + alias_of: nil ) end end entry.decls.each do |d| @@ -891,11 +914,18 @@ methods: definition.methods, name: member.new_name, location: member.location ) - definition.methods[member.new_name] = definition.methods[member.old_name] + original_method = definition.methods[member.old_name] + definition.methods[member.new_name] = Definition::Method.new( + super_method: original_method.super_method, + defs: original_method.defs, + accessibility: original_method.accessibility, + alias_of: original_method, + annotations: original_method.annotations + ) end end end end @@ -943,11 +973,12 @@ defined_in: initialize_def.defined_in, implemented_in: initialize_def.implemented_in ) end, accessibility: :public, - annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")] + annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")], + alias_of: nil ) end end entry.decls.each do |d| @@ -1027,11 +1058,12 @@ end methods[name] = Definition::Method.new( super_method: super_method, accessibility: method.accessibility, - defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) } + defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) }, + alias_of: nil ) end def try_cache(type_name, cache:) cached = _ = cache[type_name] @@ -1121,10 +1153,11 @@ member: member, defined_in: type_name, implemented_in: nil ) end, - accessibility: :public + accessibility: :public, + alias_of: nil ) definition.methods[member.name] = method end alias_members.each do |member|