lib/rbs/definition_builder.rb in rbs-3.0.2 vs lib/rbs/definition_builder.rb in rbs-3.0.3

- old
+ new

@@ -29,13 +29,14 @@ end end end def define_interface(definition, type_name, subst) - included_interfaces = ancestor_builder.one_interface_ancestors(type_name).included_interfaces or raise - interface_methods = interface_methods(included_interfaces) + included_interfaces = ancestor_builder.interface_ancestors(type_name).ancestors #: Array[Definition::Ancestor::Instance] + included_interfaces = included_interfaces.reject {|ancestor| ancestor.source == nil } + interface_methods = interface_methods(included_interfaces) methods = method_builder.build_interface(type_name) import_methods(definition, type_name, methods, interface_methods, subst) end @@ -53,11 +54,10 @@ ancestors = ancestor_builder.interface_ancestors(type_name) Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition| methods = method_builder.build_interface(type_name) one_ancestors = ancestor_builder.one_interface_ancestors(type_name) - validate_type_params(definition, methods: methods, ancestors: one_ancestors) define_interface(definition, type_name, subst) end end @@ -92,11 +92,16 @@ end define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args)) end - interface_methods = interface_methods(one_ancestors.each_included_interface.to_a) + all_interfaces = one_ancestors.each_included_interface.flat_map do |interface| + other_interfaces = ancestor_builder.interface_ancestors(interface.name).ancestors #: Array[Definition::Ancestor::Instance] + other_interfaces = other_interfaces.select {|ancestor| ancestor.source } + [interface, *other_interfaces] + end + interface_methods = interface_methods(all_interfaces) import_methods(definition, type_name, methods, interface_methods, subst) one_ancestors.each_prepended_module do |mod| mod.args.each do |arg| validate_type_presence(arg) @@ -217,10 +222,11 @@ ancestors = ancestor_builder.singleton_ancestors(type_name) self_type = Types::ClassSingleton.new(name: type_name, location: nil) Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition| one_ancestors = ancestor_builder.one_singleton_ancestors(type_name) + methods = method_builder.build_singleton(type_name) if super_class = one_ancestors.super_class case super_class when Definition::Ancestor::Instance defn = build_instance(super_class.name) @@ -231,12 +237,17 @@ definition.methods.merge!(defn.methods) definition.instance_variables.merge!(defn.instance_variables) definition.class_variables.merge!(defn.class_variables) end - one_ancestors = ancestor_builder.one_singleton_ancestors(type_name) - methods = method_builder.build_singleton(type_name) + all_interfaces = one_ancestors.each_extended_interface.flat_map do |interface| + other_interfaces = ancestor_builder.interface_ancestors(interface.name).ancestors #: Array[Definition::Ancestor::Instance] + other_interfaces = other_interfaces.select {|ancestor| ancestor.source } + [interface, *other_interfaces] + end + interface_methods = interface_methods(all_interfaces) + import_methods(definition, type_name, methods, interface_methods, Substitution.new) one_ancestors.each_extended_module do |mod| mod.args.each do |arg| validate_type_presence(arg) end @@ -277,11 +288,11 @@ end end def build_singleton(type_name) type_name = env.normalize_module_name(type_name) - + try_cache type_name, cache: singleton_cache do entry = env.class_decls[type_name] or raise "Unknown name for build_singleton: #{type_name}" ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location) ancestors = ancestor_builder.singleton_ancestors(type_name) @@ -681,12 +692,12 @@ super_method: super_method, defs: [ Definition::Method::TypeDef.new( type: method_type, member: original, - defined_in: definition.type_name, - implemented_in: definition.type_name + defined_in: defined_in, + implemented_in: implemented_in ) ], accessibility: method.accessibility, alias_of: nil ) @@ -711,11 +722,11 @@ end method_definition = Definition::Method.new( super_method: super_method, defs: existing_method.defs.map do |defn| - defn.update(implemented_in: definition.type_name) + defn.update(implemented_in: implemented_in) end, accessibility: existing_method.accessibility, alias_of: existing_method.alias_of ) end @@ -723,11 +734,11 @@ method.overloads.each do |overloading_def| overloading_def.overloads.reverse_each do |overload| type_def = Definition::Method::TypeDef.new( type: subst.empty? ? overload.method_type : overload.method_type.sub(subst), member: overloading_def, - defined_in: definition.type_name, - implemented_in: definition.type_name + defined_in: defined_in, + implemented_in: implemented_in ) method_definition.defs.unshift(type_def) end end