lib/rbs/definition_builder.rb in rbs-0.8.0 vs lib/rbs/definition_builder.rb in rbs-0.9.0

- old
+ new

@@ -383,13 +383,22 @@ yield member, accessibility end end end + def ensure_namespace!(namespace, location:) + namespace.ascend do |ns| + unless ns.empty? + NoTypeFoundError.check!(ns.to_type_name, env: env, location: location) + end + end + end + def build_instance(type_name) try_cache type_name, cache: instance_cache do entry = env.class_decls[type_name] or raise "Unknown name for build_instance: #{type_name}" + ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location) case entry when Environment::ClassEntry, Environment::ModuleEntry ancestors = instance_ancestors(type_name) self_type = Types::ClassInstance.new(name: type_name, @@ -432,10 +441,11 @@ end def build_singleton(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) case entry when Environment::ClassEntry, Environment::ModuleEntry ancestors = singleton_ancestors(type_name) self_type = Types::ClassSingleton.new(name: type_name, location: nil) @@ -1018,10 +1028,11 @@ 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}" declaration = entry.decl + ensure_namespace!(type_name.namespace, location: declaration.location) self_type = Types::Interface.new( name: type_name, args: Types::Variable.build(declaration.type_params.each.map(&:name)), location: nil @@ -1109,9 +1120,10 @@ end end def expand_alias(type_name) entry = env.alias_decls[type_name] or raise "Unknown name for expand_alias: #{type_name}" + ensure_namespace!(type_name.namespace, location: entry.decl.location) entry.decl.type end end end