lib/rbs/environment.rb in rbs-0.11.0 vs lib/rbs/environment.rb in rbs-0.12.0

- old
+ new

@@ -11,18 +11,19 @@ module ContextUtil def context @context ||= begin (outer + [decl]).each.with_object([Namespace.root]) do |decl, array| - array.unshift(array.first + decl.name.to_namespace) + first = array.first or raise + array.unshift(first + decl.name.to_namespace) end end end end class MultiEntry - D = Struct.new(:decl, :outer, keyword_init: true) do + D = _ = Struct.new(:decl, :outer, keyword_init: true) do include ContextUtil end attr_reader :name attr_reader :decls @@ -38,10 +39,12 @@ end def validate_type_params unless decls.empty? hd_decl, *tl_decls = decls + raise unless hd_decl + hd_params = hd_decl.decl.type_params hd_names = hd_params.params.map(&:name) tl_decls.each do |tl_decl| tl_params = tl_decl.decl.type_params @@ -54,10 +57,14 @@ end def type_params primary.decl.type_params end + + def primary + raise "Not implemented" + end end class ModuleEntry < MultiEntry def self_types decls.flat_map do |d| @@ -66,20 +73,20 @@ end def primary @primary ||= begin validate_type_params - decls.first + decls.first or raise("decls cannot be empty") end end end class ClassEntry < MultiEntry def primary @primary ||= begin validate_type_params - decls.find {|d| d.decl.super_class } || decls.first + decls.find {|d| d.decl.super_class } || decls.first or raise("decls cannot be empty") end end end class SingleEntry @@ -152,19 +159,21 @@ existing_entry = class_decls[name] case when decl.is_a?(AST::Declarations::Module) && existing_entry.is_a?(ModuleEntry) - # OK + # @type var existing_entry: ModuleEntry + # @type var decl: AST::Declarations::Module + existing_entry.insert(decl: decl, outer: outer) when decl.is_a?(AST::Declarations::Class) && existing_entry.is_a?(ClassEntry) - # OK + # @type var existing_entry: ClassEntry + # @type var decl: AST::Declarations::Class + existing_entry.insert(decl: decl, outer: outer) else raise DuplicatedDeclarationError.new(name, decl, existing_entry.primary.decl) end - existing_entry.insert(decl: decl, outer: outer) - prefix = outer + [decl] ns = name.to_namespace decl.each_decl do |d| insert_decl(d, outer: prefix, namespace: ns) end @@ -209,20 +218,22 @@ env end def resolve_declaration(resolver, decl, outer:, prefix:) if decl.is_a?(AST::Declarations::Global) + # @type var decl: AST::Declarations::Global return AST::Declarations::Global.new( name: decl.name, type: absolute_type(resolver, decl.type, context: [Namespace.root]), location: decl.location, comment: decl.comment ) end context = (outer + [decl]).each.with_object([Namespace.root]) do |decl, array| - array.unshift(array.first + decl.name.to_namespace) + head = array.first or raise + array.unshift(head + decl.name.to_namespace) end case decl when AST::Declarations::Class outer_ = outer + [decl] @@ -308,10 +319,13 @@ name: decl.name.with_prefix(prefix), type: absolute_type(resolver, decl.type, context: context), location: decl.location, comment: decl.comment ) + + else + raise end end def resolve_member(resolver, member, context:) case member @@ -407,10 +421,10 @@ def absolute_type_name(resolver, type_name, context:) resolver.resolve(type_name, context: context) || type_name end def absolute_type(resolver, type, context:) - type.map_type_name do |name| + type.map_type_name do |name, _, _| absolute_type_name(resolver, name, context: context) end end def inspect