lib/rbs/definition_builder/ancestor_builder.rb in rbs-3.0.2 vs lib/rbs/definition_builder/ancestor_builder.rb in rbs-3.0.3
- old
+ new
@@ -430,12 +430,13 @@
if super_class = one_ancestors.super_class
# @type var super_class: Definition::Ancestor::Instance
super_name = super_class.name
super_args = super_class.args
- super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
- ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
+ super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors).apply(super_args, location: entry.primary.decl.location)
+ super_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: super_name, source: :super) }
+ ancestors.unshift(*super_ancestors)
end
end
if self_types = one_ancestors.self_types
self_types.each do |mod|
@@ -448,23 +449,25 @@
if included_modules = one_ancestors.included_modules
included_modules.each do |mod|
name = mod.name
arg_types = mod.args
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
- ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors).apply(arg_types, location: entry.primary.decl.location)
+ mod_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: name, source: mod.source) }
+ ancestors.unshift(*mod_ancestors)
end
end
ancestors.unshift(self_ancestor)
if prepended_modules = one_ancestors.prepended_modules
prepended_modules.each do |mod|
name = mod.name
arg_types = mod.args
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
- ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors).apply(arg_types, location: entry.primary.decl.location)
+ mod_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: name, source: mod.source) }
+ ancestors.unshift(*mod_ancestors)
end
end
building_ancestors.pop
@@ -493,12 +496,13 @@
case super_class = one_ancestors.super_class
when Definition::Ancestor::Instance
super_name = super_class.name
super_args = super_class.args
- super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
- ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
+ super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors).apply(super_args, location: entry.primary.decl.location)
+ super_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: super_name, source: :super) }
+ ancestors.unshift(*super_ancestors)
when Definition::Ancestor::Singleton
super_name = super_class.name
super_ancestors = singleton_ancestors(super_name, building_ancestors: [])
@@ -507,12 +511,13 @@
extended_modules = one_ancestors.extended_modules or raise
extended_modules.each do |mod|
name = mod.name
args = mod.args
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
- ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors).apply(args, location: entry.primary.decl.location)
+ mod_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: name, source: mod.source) }
+ ancestors.unshift(*mod_ancestors)
end
ancestors.unshift(self_ancestor)
building_ancestors.pop
@@ -539,22 +544,35 @@
one_ancestors = one_interface_ancestors(type_name)
ancestors = []
included_interfaces = one_ancestors.included_interfaces or raise
included_interfaces.each do |a|
- included_ancestors = interface_ancestors(a.name, building_ancestors: building_ancestors)
-
- ancestors.unshift(*included_ancestors.apply(a.args, location: entry.decl.location))
+ included_ancestors = interface_ancestors(a.name, building_ancestors: building_ancestors).apply(a.args, location: entry.decl.location)
+ included_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: a.name, source: a.source) }
+ ancestors.unshift(*included_ancestors)
end
ancestors.unshift(self_ancestor)
building_ancestors.pop
interface_ancestors_cache[type_name] = Definition::InstanceAncestors.new(
type_name: type_name,
params: params,
ancestors: ancestors
)
+ end
+
+ def fill_ancestor_source(ancestor, name:, source:, &block)
+ case ancestor
+ when Definition::Ancestor::Instance
+ if ancestor.name == name && !ancestor.source
+ Definition::Ancestor::Instance.new(name: ancestor.name, args: ancestor.args, source: source)
+ else
+ ancestor
+ end
+ else
+ ancestor
+ end
end
end
end
end