Skip to content

Commit bc6ee45

Browse files
authored
Merge pull request #2016 from ruby/type-check
Fix type definition and type errors
2 parents d71bb51 + f4c2b7e commit bc6ee45

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/rbs/prototype/rb.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def range_element_type(types)
694694

695695
types = types.map do |t|
696696
if t.is_a?(Types::Literal)
697-
type_name = TypeName.new(name: t.literal.class.name.to_sym, namespace: Namespace.root)
697+
type_name = TypeName.new(name: t.literal.class.name&.to_sym || raise, namespace: Namespace.root)
698698
Types::ClassInstance.new(name: type_name, args: [], location: nil)
699699
else
700700
t
@@ -825,7 +825,7 @@ def sort_members!(decls)
825825
AST::Members::ClassVariable => -3,
826826
AST::Members::ClassInstanceVariable => -2,
827827
AST::Members::InstanceVariable => -1,
828-
}
828+
} #: Hash[Class, Integer]
829829
decls.sort_by! { |decl| [orders.fetch(decl.class, 0), i += 1] }
830830
end
831831
end

sig/types.rbs

+12-5
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,23 @@ module RBS
301301
end
302302

303303
class Record
304-
attr_reader all_fields: Hash[Symbol, [t, bool]]
304+
type key = Symbol | String | Integer | bool
305305

306-
attr_reader fields: Hash[Symbol, t]
306+
# All types of all files
307+
#
308+
# If the key is *required*, the second value of the tuple is `true`.
309+
# If the key is *optional*, the second value of the tuple is `false`.
310+
#
311+
attr_reader all_fields: Hash[key, [t, bool]]
312+
313+
attr_reader fields: Hash[key, t]
307314

308-
attr_reader optional_fields: Hash[Symbol, t]
315+
attr_reader optional_fields: Hash[key, t]
309316

310317
type loc = Location[bot, bot]
311318

312-
def initialize: (fields: Hash[Symbol, t], location: loc?) -> void
313-
| (all_fields: Hash[Symbol, [t, bool]], location: loc?) -> void
319+
def initialize: (fields: Hash[key, t], location: loc?) -> void
320+
| (all_fields: Hash[key, [t, bool]], location: loc?) -> void
314321

315322
include _TypeBase
316323

0 commit comments

Comments
 (0)