rbs 0.8.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/Gemfile +1 -0
  4. data/README.md +1 -1
  5. data/Rakefile +9 -4
  6. data/Steepfile +28 -0
  7. data/bin/steep +4 -0
  8. data/bin/test_runner.rb +10 -5
  9. data/docs/syntax.md +14 -1
  10. data/lib/rbs/ast/comment.rb +12 -0
  11. data/lib/rbs/ast/declarations.rb +15 -9
  12. data/lib/rbs/ast/members.rb +3 -8
  13. data/lib/rbs/buffer.rb +1 -1
  14. data/lib/rbs/cli.rb +66 -2
  15. data/lib/rbs/definition.rb +35 -16
  16. data/lib/rbs/definition_builder.rb +111 -68
  17. data/lib/rbs/environment.rb +24 -11
  18. data/lib/rbs/environment_loader.rb +55 -35
  19. data/lib/rbs/location.rb +14 -3
  20. data/lib/rbs/method_type.rb +5 -5
  21. data/lib/rbs/namespace.rb +14 -3
  22. data/lib/rbs/parser.y +8 -20
  23. data/lib/rbs/prototype/rb.rb +3 -5
  24. data/lib/rbs/prototype/rbi.rb +1 -4
  25. data/lib/rbs/prototype/runtime.rb +0 -4
  26. data/lib/rbs/substitution.rb +4 -3
  27. data/lib/rbs/test/hook.rb +1 -0
  28. data/lib/rbs/test/setup.rb +17 -12
  29. data/lib/rbs/test/setup_helper.rb +15 -0
  30. data/lib/rbs/test/tester.rb +59 -13
  31. data/lib/rbs/test/type_check.rb +43 -14
  32. data/lib/rbs/type_name.rb +18 -1
  33. data/lib/rbs/type_name_resolver.rb +10 -3
  34. data/lib/rbs/types.rb +27 -21
  35. data/lib/rbs/validator.rb +4 -0
  36. data/lib/rbs/variance_calculator.rb +8 -5
  37. data/lib/rbs/version.rb +1 -1
  38. data/lib/rbs/writer.rb +7 -3
  39. data/sig/annotation.rbs +26 -0
  40. data/sig/buffer.rbs +28 -0
  41. data/sig/builtin_names.rbs +41 -0
  42. data/sig/comment.rbs +26 -0
  43. data/sig/declarations.rbs +202 -0
  44. data/sig/definition.rbs +129 -0
  45. data/sig/definition_builder.rbs +95 -0
  46. data/sig/environment.rbs +94 -0
  47. data/sig/environment_loader.rbs +4 -0
  48. data/sig/location.rbs +52 -0
  49. data/sig/members.rbs +160 -0
  50. data/sig/method_types.rbs +40 -0
  51. data/sig/namespace.rbs +124 -0
  52. data/sig/polyfill.rbs +3 -0
  53. data/sig/rbs.rbs +3 -0
  54. data/sig/substitution.rbs +39 -0
  55. data/sig/type_name_resolver.rbs +24 -0
  56. data/sig/typename.rbs +70 -0
  57. data/sig/types.rbs +361 -0
  58. data/sig/util.rbs +13 -0
  59. data/sig/variance_calculator.rbs +35 -0
  60. data/stdlib/bigdecimal/big_decimal.rbs +887 -0
  61. data/stdlib/bigdecimal/math/big_math.rbs +142 -0
  62. data/stdlib/builtin/array.rbs +2 -1
  63. data/stdlib/builtin/builtin.rbs +0 -3
  64. data/stdlib/builtin/hash.rbs +1 -1
  65. data/stdlib/builtin/math.rbs +26 -26
  66. data/stdlib/builtin/struct.rbs +9 -10
  67. data/stdlib/date/date.rbs +1056 -0
  68. data/stdlib/date/date_time.rbs +582 -0
  69. data/stdlib/forwardable/forwardable.rbs +204 -0
  70. data/stdlib/json/json.rbs +6 -0
  71. data/stdlib/set/set.rbs +1 -1
  72. data/stdlib/uri/file.rbs +167 -0
  73. data/stdlib/uri/generic.rbs +875 -0
  74. data/stdlib/zlib/zlib.rbs +392 -0
  75. data/steep/Gemfile +3 -0
  76. data/steep/Gemfile.lock +55 -0
  77. metadata +39 -6
@@ -36,8 +36,11 @@ module RBS
36
36
  end
37
37
 
38
38
  def each_ancestor(&block)
39
- if block_given?
40
- yield super_class if super_class
39
+ if block
40
+ if s = super_class
41
+ yield s
42
+ end
43
+
41
44
  self_types&.each(&block)
42
45
  included_modules&.each(&block)
43
46
  prepended_modules&.each(&block)
@@ -108,7 +111,7 @@ module RBS
108
111
  return if with_super_classes.size <= 1
109
112
 
110
113
  super_types = with_super_classes.map do |d|
111
- super_class = d.decl.super_class
114
+ super_class = d.decl.super_class or raise
112
115
  Types::ClassInstance.new(name: super_class.name, args: super_class.args, location: nil)
113
116
  end
114
117
 
@@ -159,10 +162,10 @@ module RBS
159
162
 
160
163
  entry.self_types.each do |module_self|
161
164
  NoSelfTypeFoundError.check!(module_self, env: env)
162
- ancestors.self_types.push Definition::Ancestor::Instance.new(name: module_self.name, args: module_self.args)
165
+
166
+ self_types = ancestors.self_types or raise
167
+ self_types.push Definition::Ancestor::Instance.new(name: module_self.name, args: module_self.args)
163
168
  end
164
- else
165
- raise "Unexpected entry for: #{type_name}"
166
169
  end
167
170
 
168
171
  mixin_ancestors(entry,
@@ -208,9 +211,6 @@ module RBS
208
211
  type_name: type_name,
209
212
  super_class: Definition::Ancestor::Instance.new(name: BuiltinNames::Module.name, args: [])
210
213
  )
211
-
212
- else
213
- raise "Unexpected entry for: #{type_name}"
214
214
  end
215
215
 
216
216
  mixin_ancestors(entry,
@@ -285,33 +285,38 @@ module RBS
285
285
 
286
286
  case entry
287
287
  when Environment::ClassEntry
288
- if one_ancestors.super_class
289
- super_name = one_ancestors.super_class.name
290
- super_args = one_ancestors.super_class.args
288
+ if super_class = one_ancestors.super_class
289
+ # @type var super_class: Definition::Ancestor::Instance
290
+ super_name = super_class.name
291
+ super_args = super_class.args
291
292
 
292
293
  super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
293
294
  ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
294
295
  end
295
296
  end
296
297
 
297
- one_ancestors.included_modules.each do |mod|
298
- if mod.name.class?
299
- name = mod.name
300
- args = mod.args
301
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
302
- ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
303
- end
298
+ if included_modules = one_ancestors.included_modules
299
+ included_modules.each do |mod|
300
+ if mod.name.class?
301
+ name = mod.name
302
+ arg_types = mod.args
303
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
304
+ ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
305
+ end
306
+ end
304
307
  end
305
308
 
306
309
  ancestors.unshift(self_ancestor)
307
310
 
308
- one_ancestors.prepended_modules.each do |mod|
309
- if mod.name.class?
310
- name = mod.name
311
- args = mod.args
312
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
313
- ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
314
- end
311
+ if prepended_modules = one_ancestors.prepended_modules
312
+ prepended_modules.each do |mod|
313
+ if mod.name.class?
314
+ name = mod.name
315
+ arg_types = mod.args
316
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
317
+ ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
318
+ end
319
+ end
315
320
  end
316
321
 
317
322
  building_ancestors.pop
@@ -338,22 +343,23 @@ module RBS
338
343
 
339
344
  ancestors = []
340
345
 
341
- case one_ancestors.super_class
346
+ case super_class = one_ancestors.super_class
342
347
  when Definition::Ancestor::Instance
343
- super_name = one_ancestors.super_class.name
344
- super_args = one_ancestors.super_class.args
348
+ super_name = super_class.name
349
+ super_args = super_class.args
345
350
 
346
351
  super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
347
352
  ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
348
353
 
349
354
  when Definition::Ancestor::Singleton
350
- super_name = one_ancestors.super_class.name
355
+ super_name = super_class.name
351
356
 
352
357
  super_ancestors = singleton_ancestors(super_name, building_ancestors: [])
353
358
  ancestors.unshift(*super_ancestors.ancestors)
354
359
  end
355
360
 
356
- one_ancestors.extended_modules.each do |mod|
361
+ extended_modules = one_ancestors.extended_modules or raise
362
+ extended_modules.each do |mod|
357
363
  if mod.name.class?
358
364
  name = mod.name
359
365
  args = mod.args
@@ -385,9 +391,18 @@ module RBS
385
391
  end
386
392
  end
387
393
 
394
+ def ensure_namespace!(namespace, location:)
395
+ namespace.ascend do |ns|
396
+ unless ns.empty?
397
+ NoTypeFoundError.check!(ns.to_type_name, env: env, location: location)
398
+ end
399
+ end
400
+ end
401
+
388
402
  def build_instance(type_name)
389
403
  try_cache type_name, cache: instance_cache do
390
404
  entry = env.class_decls[type_name] or raise "Unknown name for build_instance: #{type_name}"
405
+ ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
391
406
 
392
407
  case entry
393
408
  when Environment::ClassEntry, Environment::ModuleEntry
@@ -397,17 +412,17 @@ module RBS
397
412
  location: nil)
398
413
 
399
414
  definition_pairs = ancestors.ancestors.map do |ancestor|
415
+ # @type block: [Definition::Ancestor::t, Definition]
400
416
  case ancestor
401
417
  when Definition::Ancestor::Instance
402
418
  [ancestor, build_one_instance(ancestor.name)]
403
419
  when Definition::Ancestor::Singleton
404
420
  [ancestor, build_one_singleton(ancestor.name)]
405
- else
406
- raise
407
421
  end
408
422
  end
409
423
 
410
- if entry.is_a?(Environment::ModuleEntry)
424
+ case entry
425
+ when Environment::ModuleEntry
411
426
  entry.self_types.each do |module_self|
412
427
  ancestor = Definition::Ancestor::Instance.new(name: module_self.name, args: module_self.args)
413
428
  definition_pairs.push(
@@ -424,9 +439,6 @@ module RBS
424
439
  end
425
440
 
426
441
  merge_definitions(type_name, definition_pairs, entry: entry, self_type: self_type, ancestors: ancestors)
427
-
428
- else
429
- raise
430
442
  end
431
443
  end
432
444
  end
@@ -434,6 +446,7 @@ module RBS
434
446
  def build_singleton(type_name)
435
447
  try_cache type_name, cache: singleton_cache do
436
448
  entry = env.class_decls[type_name] or raise "Unknown name for build_singleton: #{type_name}"
449
+ ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
437
450
 
438
451
  case entry
439
452
  when Environment::ClassEntry, Environment::ModuleEntry
@@ -446,6 +459,7 @@ module RBS
446
459
  )
447
460
 
448
461
  definition_pairs = ancestors.ancestors.map do |ancestor|
462
+ # @type block: [Definition::Ancestor::t, Definition]
449
463
  case ancestor
450
464
  when Definition::Ancestor::Instance
451
465
  [ancestor, build_one_instance(ancestor.name)]
@@ -464,20 +478,18 @@ module RBS
464
478
  ancestor,
465
479
  definition
466
480
  ]
467
- else
468
- raise
469
481
  end
470
482
  end
471
483
 
472
484
  merge_definitions(type_name, definition_pairs, entry: entry, self_type: self_type, ancestors: ancestors)
473
- else
474
- raise
475
485
  end
476
486
  end
477
487
  end
478
488
 
479
489
  def method_definition_members(type_name, entry, kind:)
490
+ # @type var interface_methods: Hash[Symbol, [Definition::Method, AST::Members::t]]
480
491
  interface_methods = {}
492
+ # @type var methods: Hash[Symbol, Array[[AST::Members::MethodDefinition, Definition::accessibility]]]
481
493
  methods = {}
482
494
 
483
495
  entry.decls.each do |d|
@@ -524,11 +536,14 @@ module RBS
524
536
  end
525
537
  end
526
538
 
539
+ # @type var result: Hash[Symbol, member_detail]
527
540
  result = {}
528
541
 
529
542
  interface_methods.each do |name, pair|
530
543
  method_definition, _ = pair
531
- result[name] = [:public, method_definition]
544
+ # @type var detail: member_detail
545
+ detail = [:public, method_definition, nil, []]
546
+ result[name] = detail
532
547
  end
533
548
 
534
549
  methods.each do |method_name, array|
@@ -552,14 +567,14 @@ module RBS
552
567
  )
553
568
  end
554
569
 
555
- result[method_name] += array.map(&:first)
570
+ result[method_name][3].push(*array.map(&:first))
556
571
  else
557
572
  case
558
573
  when array.size == 1 && !array[0][0].overload?
559
574
  member, visibility = array[0]
560
- result[method_name] = [visibility, nil, member]
575
+ result[method_name] = [visibility, nil, member, []]
561
576
 
562
- when array.count {|pair| !pair[0].overload? } == 1
577
+ else
563
578
  visibilities = array.group_by {|pair| pair[1] }
564
579
 
565
580
  if visibilities.size > 1
@@ -572,15 +587,7 @@ module RBS
572
587
  end
573
588
 
574
589
  overloads, primary = array.map(&:first).partition(&:overload?)
575
- result[method_name] = [array[0][1], nil, *primary, *overloads]
576
-
577
- else
578
- raise InvalidOverloadMethodError.new(
579
- type_name: type_name,
580
- method_name: method_name,
581
- kind: :instance,
582
- members: array.map(&:first)
583
- )
590
+ result[method_name] = [array[0][1], nil, primary[0], overloads]
584
591
  end
585
592
  end
586
593
  end
@@ -599,7 +606,13 @@ module RBS
599
606
 
600
607
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
601
608
  method_definition_members(type_name, entry, kind: :instance).each do |method_name, array|
602
- visibility, method_def, *members = array
609
+ visibility, method_def, primary_member, overload_members = array
610
+
611
+ members = if primary_member
612
+ [primary_member, *overload_members]
613
+ else
614
+ overload_members
615
+ end
603
616
 
604
617
  m = if method_def
605
618
  Definition::Method.new(
@@ -768,9 +781,9 @@ module RBS
768
781
 
769
782
  errors = []
770
783
 
771
- if decl.is_a?(AST::Declarations::Class)
772
- if decl.super_class
773
- super_class = decl.super_class
784
+ case decl
785
+ when AST::Declarations::Class
786
+ if super_class = decl.super_class
774
787
  result = calculator.in_inherit(name: super_class.name, args: super_class.args, variables: param_names)
775
788
 
776
789
  validate_params_with type_params, result: result do |param|
@@ -781,6 +794,8 @@ module RBS
781
794
  end
782
795
  end
783
796
 
797
+ # @type var result: VarianceCalculator::Result
798
+
784
799
  decl.members.each do |member|
785
800
  case member
786
801
  when AST::Members::Include
@@ -828,7 +843,13 @@ module RBS
828
843
 
829
844
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
830
845
  method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array|
831
- visibility, method_def, *members = array
846
+ visibility, method_def, primary_member, overload_members = array
847
+
848
+ members = if primary_member
849
+ [primary_member, *overload_members]
850
+ else
851
+ overload_members
852
+ end
832
853
 
833
854
  m = Definition::Method.new(
834
855
  super_method: nil,
@@ -880,7 +901,7 @@ module RBS
880
901
  end
881
902
 
882
903
  unless definition.methods.key?(:new)
883
- instance = build_one_instance(type_name)
904
+ instance = build_instance(type_name)
884
905
  initialize = instance.methods[:initialize]
885
906
 
886
907
  if initialize
@@ -924,7 +945,8 @@ module RBS
924
945
  implemented_in: nil
925
946
  )
926
947
  end,
927
- accessibility: :public
948
+ accessibility: :public,
949
+ annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")]
928
950
  )
929
951
  end
930
952
  end
@@ -954,7 +976,7 @@ module RBS
954
976
 
955
977
  def merge_definitions(type_name, pairs, entry:, self_type:, ancestors:)
956
978
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
957
- pairs.reverse_each do |(ancestor, current_definition)|
979
+ pairs.reverse_each do |ancestor, current_definition|
958
980
  sub = case ancestor
959
981
  when Definition::Ancestor::Instance
960
982
  Substitution.build(current_definition.type_params, ancestor.args)
@@ -962,8 +984,16 @@ module RBS
962
984
  Substitution.build([], [])
963
985
  end
964
986
 
987
+ # @type var kind: method_kind
988
+ kind = case ancestor
989
+ when Definition::Ancestor::Instance
990
+ :instance
991
+ when Definition::Ancestor::Singleton
992
+ :singleton
993
+ end
994
+
965
995
  current_definition.methods.each do |name, method|
966
- merge_method definition.methods, name, method, sub
996
+ merge_method type_name, definition.methods, name, method, sub, kind: kind
967
997
  end
968
998
 
969
999
  current_definition.instance_variables.each do |name, variable|
@@ -987,18 +1017,25 @@ module RBS
987
1017
  )
988
1018
  end
989
1019
 
990
- def merge_method(methods, name, method, sub)
1020
+ def merge_method(type_name, methods, name, method, sub, kind:)
991
1021
  super_method = methods[name]
992
1022
 
1023
+ defs = if method.defs.all? {|d| d.overload? }
1024
+ raise InvalidOverloadMethodError.new(type_name: type_name, method_name: name, kind: kind, members: method.members) unless super_method
1025
+ method.defs + super_method.defs
1026
+ else
1027
+ method.defs
1028
+ end
1029
+
993
1030
  methods[name] = Definition::Method.new(
994
1031
  super_method: super_method,
995
1032
  accessibility: method.accessibility,
996
- defs: sub.mapping.empty? ? method.defs : method.defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
1033
+ defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
997
1034
  )
998
1035
  end
999
1036
 
1000
1037
  def try_cache(type_name, cache:)
1001
- cached = cache[type_name]
1038
+ cached = _ = cache[type_name]
1002
1039
 
1003
1040
  case cached
1004
1041
  when Definition
@@ -1010,9 +1047,11 @@ module RBS
1010
1047
  begin
1011
1048
  cache[type_name] = yield
1012
1049
  rescue => ex
1013
- cache[type_name] = nil
1050
+ cache.delete(type_name)
1014
1051
  raise ex
1015
1052
  end
1053
+ else
1054
+ raise
1016
1055
  end
1017
1056
  end
1018
1057
 
@@ -1020,6 +1059,7 @@ module RBS
1020
1059
  try_cache(type_name, cache: interface_cache) do
1021
1060
  entry = env.interface_decls[type_name] or raise "Unknown name for build_interface: #{type_name}"
1022
1061
  declaration = entry.decl
1062
+ ensure_namespace!(type_name.namespace, location: declaration.location)
1023
1063
 
1024
1064
  self_type = Types::Interface.new(
1025
1065
  name: type_name,
@@ -1049,7 +1089,9 @@ module RBS
1049
1089
  mixin = build_interface(member.name)
1050
1090
 
1051
1091
  args = member.args
1052
- type_params = mixin.entry.decl.type_params
1092
+ # @type var interface_entry: Environment::SingleEntry[TypeName, AST::Declarations::Interface]
1093
+ interface_entry = _ = mixin.entry
1094
+ type_params = interface_entry.decl.type_params
1053
1095
 
1054
1096
  InvalidTypeApplicationError.check!(
1055
1097
  type_name: type_name,
@@ -1111,6 +1153,7 @@ module RBS
1111
1153
 
1112
1154
  def expand_alias(type_name)
1113
1155
  entry = env.alias_decls[type_name] or raise "Unknown name for expand_alias: #{type_name}"
1156
+ ensure_namespace!(type_name.namespace, location: entry.decl.location)
1114
1157
  entry.decl.type
1115
1158
  end
1116
1159
  end
@@ -13,14 +13,15 @@ module RBS
13
13
  def context
14
14
  @context ||= begin
15
15
  (outer + [decl]).each.with_object([Namespace.root]) do |decl, array|
16
- array.unshift(array.first + decl.name.to_namespace)
16
+ first = array.first or raise
17
+ array.unshift(first + decl.name.to_namespace)
17
18
  end
18
19
  end
19
20
  end
20
21
  end
21
22
 
22
23
  class MultiEntry
23
- D = Struct.new(:decl, :outer, keyword_init: true) do
24
+ D = _ = Struct.new(:decl, :outer, keyword_init: true) do
24
25
  include ContextUtil
25
26
  end
26
27
 
@@ -40,6 +41,8 @@ module RBS
40
41
  def validate_type_params
41
42
  unless decls.empty?
42
43
  hd_decl, *tl_decls = decls
44
+ raise unless hd_decl
45
+
43
46
  hd_params = hd_decl.decl.type_params
44
47
  hd_names = hd_params.params.map(&:name)
45
48
 
@@ -56,6 +59,10 @@ module RBS
56
59
  def type_params
57
60
  primary.decl.type_params
58
61
  end
62
+
63
+ def primary
64
+ raise "Not implemented"
65
+ end
59
66
  end
60
67
 
61
68
  class ModuleEntry < MultiEntry
@@ -68,7 +75,7 @@ module RBS
68
75
  def primary
69
76
  @primary ||= begin
70
77
  validate_type_params
71
- decls.first
78
+ decls.first or raise("decls cannot be empty")
72
79
  end
73
80
  end
74
81
  end
@@ -77,7 +84,7 @@ module RBS
77
84
  def primary
78
85
  @primary ||= begin
79
86
  validate_type_params
80
- decls.find {|d| d.decl.super_class } || decls.first
87
+ decls.find {|d| d.decl.super_class } || decls.first or raise("decls cannot be empty")
81
88
  end
82
89
  end
83
90
  end
@@ -154,15 +161,17 @@ module RBS
154
161
 
155
162
  case
156
163
  when decl.is_a?(AST::Declarations::Module) && existing_entry.is_a?(ModuleEntry)
157
- # OK
164
+ # @type var existing_entry: ModuleEntry
165
+ # @type var decl: AST::Declarations::Module
166
+ existing_entry.insert(decl: decl, outer: outer)
158
167
  when decl.is_a?(AST::Declarations::Class) && existing_entry.is_a?(ClassEntry)
159
- # OK
168
+ # @type var existing_entry: ClassEntry
169
+ # @type var decl: AST::Declarations::Class
170
+ existing_entry.insert(decl: decl, outer: outer)
160
171
  else
161
172
  raise DuplicatedDeclarationError.new(name, decl, existing_entry.primary.decl)
162
173
  end
163
174
 
164
- existing_entry.insert(decl: decl, outer: outer)
165
-
166
175
  prefix = outer + [decl]
167
176
  ns = name.to_namespace
168
177
  decl.each_decl do |d|
@@ -211,6 +220,7 @@ module RBS
211
220
 
212
221
  def resolve_declaration(resolver, decl, outer:, prefix:)
213
222
  if decl.is_a?(AST::Declarations::Global)
223
+ # @type var decl: AST::Declarations::Global
214
224
  return AST::Declarations::Global.new(
215
225
  name: decl.name,
216
226
  type: absolute_type(resolver, decl.type, context: [Namespace.root]),
@@ -220,7 +230,8 @@ module RBS
220
230
  end
221
231
 
222
232
  context = (outer + [decl]).each.with_object([Namespace.root]) do |decl, array|
223
- array.unshift(array.first + decl.name.to_namespace)
233
+ head = array.first or raise
234
+ array.unshift(head + decl.name.to_namespace)
224
235
  end
225
236
 
226
237
  case decl
@@ -310,6 +321,9 @@ module RBS
310
321
  location: decl.location,
311
322
  comment: decl.comment
312
323
  )
324
+
325
+ else
326
+ raise
313
327
  end
314
328
  end
315
329
 
@@ -325,7 +339,6 @@ module RBS
325
339
  comment: member.comment,
326
340
  overload: member.overload?,
327
341
  annotations: member.annotations,
328
- attributes: member.attributes,
329
342
  location: member.location
330
343
  )
331
344
  when AST::Members::AttrAccessor
@@ -410,7 +423,7 @@ module RBS
410
423
  end
411
424
 
412
425
  def absolute_type(resolver, type, context:)
413
- type.map_type_name do |name|
426
+ type.map_type_name do |name, _, _|
414
427
  absolute_type_name(resolver, name, context: context)
415
428
  end
416
429
  end