lib/rbs/definition_builder.rb in rbs-3.5.3 vs lib/rbs/definition_builder.rb in rbs-3.6.0.dev.1

- old
+ new

@@ -35,11 +35,11 @@ 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) + import_methods(definition, type_name, methods, interface_methods, subst, nil) end def build_interface(type_name) try_cache(type_name, cache: interface_cache) do entry = env.interface_decls[type_name] or raise "Unknown name for build_interface: #{type_name}" @@ -84,10 +84,23 @@ def define_instance(definition, type_name, subst) one_ancestors = ancestor_builder.one_instance_ancestors(type_name) methods = method_builder.build_instance(type_name) + self_type_methods = one_ancestors.each_self_type.with_object({}) do |self_type, hash| #$ Hash[Symbol, Definition::Method] + self_type.args.each do |arg| + validate_type_presence(arg) + end + + self_type_defn = self_type.name.interface? ? build_interface(self_type.name) : build_instance(self_type.name) + + s = subst + tapp_subst(self_type.name, self_type.args) + self_type_defn.methods.each do |method_name, method_def| + hash[method_name] = method_def.sub(s) + end + end + one_ancestors.each_included_module do |mod| mod.args.each do |arg| validate_type_presence(arg) end @@ -98,11 +111,11 @@ 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) + import_methods(definition, type_name, methods, interface_methods, subst, self_type_methods) one_ancestors.each_prepended_module do |mod| mod.args.each do |arg| validate_type_presence(arg) end @@ -252,11 +265,11 @@ 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) + import_methods(definition, type_name, methods, interface_methods, Substitution.new, nil) entry.decls.each do |d| d.decl.members.each do |member| case member when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter @@ -527,11 +540,11 @@ type: type, declared_in: type_name ) end - def import_methods(definition, module_name, module_methods, interfaces_methods, subst) + def import_methods(definition, module_name, module_methods, interfaces_methods, subst, self_type_methods) new_methods = {} #: Hash[Symbol, Definition::Method] interface_method_duplicates = Set[] #: Set[Symbol] interfaces_methods.each do |interface, (methods, member)| unless interface.args.empty? @@ -565,10 +578,11 @@ define_method( new_methods, definition, method, subst_, + nil, defined_in: interface.name, implemented_in: module_name ) end end @@ -577,23 +591,24 @@ define_method( new_methods, definition, method, subst, + self_type_methods, defined_in: module_name, implemented_in: module_name.interface? ? nil : module_name ) end definition.methods.merge!(new_methods) end - def define_method(methods, definition, method, subst, defined_in:, implemented_in: defined_in) + def define_method(methods, definition, method, subst, self_type_methods, defined_in:, implemented_in: defined_in) existing_method = methods[method.name] || definition.methods[method.name] case original = method.original when AST::Members::Alias - original_method = methods[original.old_name] || definition.methods[original.old_name] + original_method = methods[original.old_name] || definition.methods[original.old_name] || self_type_methods&.fetch(original.old_name, nil) unless original_method raise UnknownMethodAliasError.new( type_name: definition.type_name, original_name: original.old_name,