diff --git a/lib/rbs/prototype/rb.rb b/lib/rbs/prototype/rb.rb index 88f3a412d..97c9a6bfe 100644 --- a/lib/rbs/prototype/rb.rb +++ b/lib/rbs/prototype/rb.rb @@ -694,7 +694,7 @@ def range_element_type(types) types = types.map do |t| if t.is_a?(Types::Literal) - type_name = TypeName.new(name: t.literal.class.name.to_sym, namespace: Namespace.root) + type_name = TypeName.new(name: t.literal.class.name&.to_sym || raise, namespace: Namespace.root) Types::ClassInstance.new(name: type_name, args: [], location: nil) else t @@ -825,7 +825,7 @@ def sort_members!(decls) AST::Members::ClassVariable => -3, AST::Members::ClassInstanceVariable => -2, AST::Members::InstanceVariable => -1, - } + } #: Hash[Class, Integer] decls.sort_by! { |decl| [orders.fetch(decl.class, 0), i += 1] } end end diff --git a/sig/types.rbs b/sig/types.rbs index e9171300b..7b33abc90 100644 --- a/sig/types.rbs +++ b/sig/types.rbs @@ -301,16 +301,23 @@ module RBS end class Record - attr_reader all_fields: Hash[Symbol, [t, bool]] + type key = Symbol | String | Integer | bool - attr_reader fields: Hash[Symbol, t] + # All types of all files + # + # If the key is *required*, the second value of the tuple is `true`. + # If the key is *optional*, the second value of the tuple is `false`. + # + attr_reader all_fields: Hash[key, [t, bool]] + + attr_reader fields: Hash[key, t] - attr_reader optional_fields: Hash[Symbol, t] + attr_reader optional_fields: Hash[key, t] type loc = Location[bot, bot] - def initialize: (fields: Hash[Symbol, t], location: loc?) -> void - | (all_fields: Hash[Symbol, [t, bool]], location: loc?) -> void + def initialize: (fields: Hash[key, t], location: loc?) -> void + | (all_fields: Hash[key, [t, bool]], location: loc?) -> void include _TypeBase