rbs 3.5.3 → 3.6.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependabot.yml +5 -1
  3. data/.github/workflows/ruby.yml +2 -18
  4. data/.github/workflows/windows.yml +26 -0
  5. data/.rubocop.yml +28 -1
  6. data/CHANGELOG.md +58 -0
  7. data/Rakefile +8 -2
  8. data/core/array.rbs +10 -10
  9. data/core/basic_object.rbs +4 -4
  10. data/core/builtin.rbs +4 -4
  11. data/core/dir.rbs +1 -1
  12. data/core/enumerable.rbs +17 -11
  13. data/core/enumerator/product.rbs +1 -1
  14. data/core/enumerator.rbs +9 -2
  15. data/core/errors.rbs +1 -1
  16. data/core/exception.rbs +1 -1
  17. data/core/fiber.rbs +1 -1
  18. data/core/file.rbs +1 -1
  19. data/core/global_variables.rbs +2 -2
  20. data/core/integer.rbs +4 -4
  21. data/core/kernel.rbs +69 -40
  22. data/core/method.rbs +98 -7
  23. data/core/module.rbs +3 -3
  24. data/core/proc.rbs +184 -23
  25. data/core/ractor.rbs +1 -1
  26. data/core/random.rbs +1 -1
  27. data/core/range.rbs +30 -0
  28. data/core/rbs/unnamed/env_class.rbs +7 -7
  29. data/core/rbs/unnamed/random.rbs +14 -14
  30. data/core/refinement.rbs +16 -26
  31. data/core/regexp.rbs +2 -2
  32. data/core/symbol.rbs +34 -26
  33. data/core/thread.rbs +8 -7
  34. data/core/trace_point.rbs +12 -12
  35. data/core/unbound_method.rbs +1 -1
  36. data/docs/syntax.md +26 -12
  37. data/ext/rbs_extension/lexer.c +1 -1
  38. data/ext/rbs_extension/lexer.h +5 -0
  39. data/ext/rbs_extension/lexer.re +1 -1
  40. data/ext/rbs_extension/lexstate.c +16 -0
  41. data/ext/rbs_extension/location.c +27 -39
  42. data/ext/rbs_extension/location.h +7 -2
  43. data/ext/rbs_extension/parser.c +119 -51
  44. data/ext/rbs_extension/ruby_objs.c +2 -1
  45. data/ext/rbs_extension/ruby_objs.h +1 -1
  46. data/lib/rbs/ast/declarations.rb +36 -0
  47. data/lib/rbs/ast/type_param.rb +71 -15
  48. data/lib/rbs/ast/visitor.rb +137 -0
  49. data/lib/rbs/buffer.rb +5 -0
  50. data/lib/rbs/cli/validate.rb +81 -7
  51. data/lib/rbs/cli.rb +3 -3
  52. data/lib/rbs/definition.rb +2 -1
  53. data/lib/rbs/definition_builder/ancestor_builder.rb +30 -4
  54. data/lib/rbs/definition_builder.rb +21 -6
  55. data/lib/rbs/environment_loader.rb +1 -1
  56. data/lib/rbs/errors.rb +8 -3
  57. data/lib/rbs/file_finder.rb +9 -12
  58. data/lib/rbs/location_aux.rb +2 -6
  59. data/lib/rbs/locator.rb +8 -5
  60. data/lib/rbs/prototype/rbi.rb +2 -1
  61. data/lib/rbs/prototype/runtime.rb +3 -2
  62. data/lib/rbs/sorter.rb +9 -6
  63. data/lib/rbs/test/type_check.rb +13 -0
  64. data/lib/rbs/types.rb +11 -0
  65. data/lib/rbs/validator.rb +2 -2
  66. data/lib/rbs/vendorer.rb +3 -3
  67. data/lib/rbs/version.rb +1 -1
  68. data/lib/rbs.rb +1 -0
  69. data/sig/declarations.rbs +6 -0
  70. data/sig/definition.rbs +1 -1
  71. data/sig/definition_builder.rbs +3 -1
  72. data/sig/errors.rbs +3 -2
  73. data/sig/file_finder.rbs +24 -2
  74. data/sig/location.rbs +0 -3
  75. data/sig/method_types.rbs +1 -1
  76. data/sig/sorter.rbs +1 -1
  77. data/sig/type_param.rbs +41 -9
  78. data/sig/types.rbs +12 -0
  79. data/sig/visitor.rbs +47 -0
  80. data/stdlib/csv/0/csv.rbs +44 -6
  81. data/stdlib/digest/0/digest.rbs +22 -28
  82. data/stdlib/ipaddr/0/ipaddr.rbs +1 -1
  83. data/stdlib/kconv/0/kconv.rbs +166 -0
  84. data/stdlib/net-http/0/net-http.rbs +2 -2
  85. data/stdlib/psych/0/store.rbs +1 -1
  86. data/stdlib/uri/0/ldap.rbs +1 -1
  87. data/stdlib/zlib/0/deflate.rbs +1 -1
  88. data/stdlib/zlib/0/gzip_reader.rbs +5 -1
  89. metadata +6 -2
data/core/thread.rbs CHANGED
@@ -382,7 +382,7 @@ class Thread < Object
382
382
  # If you're going to subclass Thread, be sure to call super in your `initialize`
383
383
  # method, otherwise a ThreadError will be raised.
384
384
  #
385
- def initialize: (*untyped) { (*untyped) -> void } -> void
385
+ def initialize: (*untyped) { (?) -> void } -> void
386
386
 
387
387
  # <!--
388
388
  # rdoc-file=thread.c
@@ -1178,7 +1178,7 @@ class Thread < Object
1178
1178
  # calling `start` in that subclass will not invoke the subclass's `initialize`
1179
1179
  # method.
1180
1180
  #
1181
- def self.start: (*untyped args) { (*untyped) -> void } -> instance
1181
+ def self.start: (*untyped args) { (?) -> void } -> instance
1182
1182
 
1183
1183
  # <!--
1184
1184
  # rdoc-file=thread.c
@@ -1545,7 +1545,7 @@ end
1545
1545
  #
1546
1546
  # consumer.join
1547
1547
  #
1548
- class Thread::Queue < Object
1548
+ class Thread::Queue[Elem = untyped] < Object
1549
1549
  # <!-- rdoc-file=thread_sync.c -->
1550
1550
  # Pushes the given `object` to the queue.
1551
1551
  #
@@ -1661,7 +1661,7 @@ class Thread::Queue < Object
1661
1661
  # If `timeout` seconds have passed and no data is available `nil` is returned.
1662
1662
  # If `timeout` is `0` it returns immediately.
1663
1663
  #
1664
- def pop: (?boolish non_block, ?timeout: _ToF?) -> untyped
1664
+ def pop: (?boolish non_block, ?timeout: _ToF?) -> Elem?
1665
1665
 
1666
1666
  # <!--
1667
1667
  # rdoc-file=thread_sync.c
@@ -1671,7 +1671,7 @@ class Thread::Queue < Object
1671
1671
  # -->
1672
1672
  # Pushes the given `object` to the queue.
1673
1673
  #
1674
- def push: (untyped obj) -> void
1674
+ def push: (Elem obj) -> void
1675
1675
 
1676
1676
  # <!--
1677
1677
  # rdoc-file=thread_sync.rb
@@ -1692,7 +1692,7 @@ end
1692
1692
  #
1693
1693
  # See Thread::Queue for an example of how a Thread::SizedQueue works.
1694
1694
  #
1695
- class Thread::SizedQueue < Thread::Queue
1695
+ class Thread::SizedQueue[Elem = untyped] < Thread::Queue[Elem]
1696
1696
  # <!--
1697
1697
  # rdoc-file=thread_sync.rb
1698
1698
  # - <<(object, non_block = false, timeout: nil)
@@ -1755,7 +1755,8 @@ class Thread::SizedQueue < Thread::Queue
1755
1755
  # If `timeout` seconds have passed and no space is available `nil` is returned.
1756
1756
  # If `timeout` is `0` it returns immediately. Otherwise it returns `self`.
1757
1757
  #
1758
- def push: (untyped obj, ?boolish non_block, timeout: _ToF?) -> void
1758
+ def push: (Elem obj, ?boolish non_block) -> void
1759
+ | (Elem obj, timeout: _ToF?) -> self?
1759
1760
  end
1760
1761
 
1761
1762
  class ConditionVariable = Thread::ConditionVariable
data/core/trace_point.rbs CHANGED
@@ -63,7 +63,7 @@
63
63
  # `:script_compiled`
64
64
  # : new Ruby code compiled (with `eval`, `load` or `require`)
65
65
  #
66
- class TracePoint < Object
66
+ class TracePoint
67
67
  # <!--
68
68
  # rdoc-file=trace_point.rb
69
69
  # - TracePoint.new(*events) { |obj| block } -> obj
@@ -110,7 +110,7 @@ class TracePoint < Object
110
110
  #
111
111
  # Access from other threads is also forbidden.
112
112
  #
113
- def initialize: (*Symbol events) { (TracePoint tp) -> void } -> void
113
+ def self.new: (*_ToSym events) { (instance tp) -> void } -> instance
114
114
 
115
115
  # <!--
116
116
  # rdoc-file=trace_point.rb
@@ -172,7 +172,7 @@ class TracePoint < Object
172
172
  # (note that we needed to filter out calls by itself from :line handler,
173
173
  # otherwise it will call itself infinitely).
174
174
  #
175
- def self.allow_reentry: () { () -> void } -> void
175
+ def self.allow_reentry: [T] () { (nil) -> T } -> T
176
176
 
177
177
  # <!--
178
178
  # rdoc-file=trace_point.rb
@@ -199,7 +199,7 @@ class TracePoint < Object
199
199
  #
200
200
  # trace.enabled? #=> true
201
201
  #
202
- def self.trace: (*Symbol events) { (TracePoint tp) -> void } -> TracePoint
202
+ def self.trace: (*_ToSym events) { (instance tp) -> void } -> instance
203
203
 
204
204
  # <!--
205
205
  # rdoc-file=trace_point.rb
@@ -218,7 +218,7 @@ class TracePoint < Object
218
218
  # -->
219
219
  # Return the called name of the method being called
220
220
  #
221
- def callee_id: () -> Symbol
221
+ def callee_id: () -> Symbol?
222
222
 
223
223
  # <!--
224
224
  # rdoc-file=trace_point.rb
@@ -257,7 +257,7 @@ class TracePoint < Object
257
257
  # C.foo
258
258
  # end
259
259
  #
260
- def defined_class: () -> Module
260
+ def defined_class: () -> (Class | Module)?
261
261
 
262
262
  # <!--
263
263
  # rdoc-file=trace_point.rb
@@ -293,7 +293,7 @@ class TracePoint < Object
293
293
  # #=> RuntimeError: access from outside
294
294
  #
295
295
  def disable: () -> bool
296
- | () { () -> void } -> void
296
+ | [T] () { () -> T } -> T
297
297
 
298
298
  # <!--
299
299
  # rdoc-file=trace_point.rb
@@ -352,8 +352,8 @@ class TracePoint < Object
352
352
  # trace.enable { p tp.lineno }
353
353
  # #=> RuntimeError: access from outside
354
354
  #
355
- def enable: (?target: (Method | UnboundMethod | Proc)?, ?target_line: Integer?, ?target_thread: Thread?) -> bool
356
- | [R] (?target: (Method | UnboundMethod | Proc)?, ?target_line: Integer?, ?target_thread: Thread?) { () -> R } -> R
355
+ def enable: (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) -> bool
356
+ | [T] (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) { () -> T } -> T
357
357
 
358
358
  # <!--
359
359
  # rdoc-file=trace_point.rb
@@ -395,7 +395,7 @@ class TracePoint < Object
395
395
  # -->
396
396
  # Return the name at the definition of the method being called
397
397
  #
398
- def method_id: () -> Symbol
398
+ def method_id: () -> Symbol?
399
399
 
400
400
  # <!--
401
401
  # rdoc-file=trace_point.rb
@@ -412,7 +412,7 @@ class TracePoint < Object
412
412
  # Return the parameters definition of the method or block that the current hook
413
413
  # belongs to. Format is the same as for Method#parameters
414
414
  #
415
- def parameters: () -> ::Array[[ :req | :opt | :rest | :keyreq | :key | :keyrest | :block, Symbol ] | [ :rest | :keyrest ]]
415
+ def parameters: () -> Method::param_types?
416
416
 
417
417
  # <!--
418
418
  # rdoc-file=trace_point.rb
@@ -421,7 +421,7 @@ class TracePoint < Object
421
421
  # Value from exception raised on the `:raise` event, or rescued on the `:rescue`
422
422
  # event.
423
423
  #
424
- def raised_exception: () -> untyped
424
+ def raised_exception: () -> Exception
425
425
 
426
426
  # <!--
427
427
  # rdoc-file=trace_point.rb
@@ -325,5 +325,5 @@ class UnboundMethod
325
325
  # arguments. This is semantically equivalent to `umeth.bind(recv).call(args,
326
326
  # ...)`.
327
327
  #
328
- def bind_call: (untyped recv, *untyped, **untyped) ?{ (*untyped, **untyped) -> untyped } -> untyped
328
+ def bind_call: (untyped recv, *untyped, **untyped) ?{ (?) -> untyped } -> untyped
329
329
  end
data/docs/syntax.md CHANGED
@@ -64,7 +64,7 @@ Interface type denotes _type of a value which can be a subtype of the interface_
64
64
 
65
65
  ```rbs
66
66
  _ToS # _ToS interface
67
- ::MyApp::_Each[String] # Interface name with namespace and type application
67
+ ::Enumerator::_Each[String] # Interface name with namespace and type application
68
68
  ```
69
69
 
70
70
  ### Alias type
@@ -424,8 +424,10 @@ _visibility_ ::= `public` | `private`
424
424
 
425
425
  _attribute-type_ ::= `attr_reader` | `attr_writer` | `attr_accessor`
426
426
 
427
- _include-member_ ::= `include` _class-name_ _type-arguments_
428
- | `include` _interface-name_ _type-arguments_
427
+ _include-member_ ::= _include-class-member_
428
+ | _include-interface-member_
429
+ _include-class-member_ ::= `include` _class-name_ _type-arguments_
430
+ _include-interface-member_ :== `include` _interface-name_ _type-arguments_
429
431
  _extend-member_ ::= `extend` _class-name_ _type-arguments_
430
432
  | `extend` _interface-name_ _type-arguments_
431
433
  _prepend-member_ ::= `prepend` _class-name_ _type-arguments_
@@ -621,7 +623,7 @@ _module-self-types_ ::= _class-name_ _type-arguments_ `,` _module-self-types_
621
623
  _interface-decl_ ::= `interface` _interface-name_ _module-type-parameters_ _interface-members_ `end`
622
624
 
623
625
  _interface-members_ ::= _method-member_ # Method
624
- | _include-member_ # Mixin (include)
626
+ | _include-interface-member_ # Mixin (include)
625
627
  | _alias-member_ # Alias
626
628
 
627
629
  _type-alias-decl_ ::= `type` _alias-name_ _module-type-parameters_ `=` _type_
@@ -750,16 +752,15 @@ $LOAD_PATH: Array[String]
750
752
  ### Generics
751
753
 
752
754
  ```markdown
753
- _module-type-parameter_ ::= _generics-unchecked_ _generics-variance_ _type-variable_ _generics-bound_
755
+ _module-type-parameter_ ::= _generics-unchecked_ _generics-variance_ _type-variable_ _generics-bound_ _default-type_
754
756
 
755
757
  _method-type-param_ ::= _type-variable_ _generics-bound_
756
758
 
757
- _generics-bound_ ::= (No type bound)
758
- | `<` _bound-type_ (The generics parameter is bounded)
759
+ _generics-bound_ ::= (No type bound)
760
+ | `<` _type_ (The generics parameter is bounded)
759
761
 
760
- _bound-type_ ::= _class-name_ _type-arguments_ (Class instance type)
761
- | _interface-name_ _type-arguments_ (Interface type)
762
- | `singleton(` _class-name_ `)` (Class singleton type)
762
+ _default-type_ ::= (No default type)
763
+ | `=` _type_ (The generics parameter has default type)
763
764
 
764
765
  _generics-variance_ ::= (Invariant)
765
766
  | `out` (Covariant)
@@ -826,14 +827,27 @@ class PrettyPrint[T < _Output]
826
827
  end
827
828
  ```
828
829
 
829
- If a type parameter has an upper bound, the type parameter must be instantiated with types that is a subclass of the upper bound.
830
+ If a type parameter has an upper bound, the type parameter must be instantiated with types that is a subtype of the upper bound.
830
831
 
831
832
  ```rbs
832
833
  type str_printer = PrettyPrint[String] # OK
833
834
  type int_printer = PrettyPrint[Integer] # Type error
834
835
  ```
835
836
 
836
- The upper bound must be one of a class instance type, interface type, or class singleton type.
837
+ The generics type parameter of modules, classes, interfaces, or type aliases can have a default type.
838
+
839
+ ```rbs
840
+ interface _Foo[T = untyped]
841
+ end
842
+
843
+ interface _Bar[T, S = untyped]
844
+ end
845
+
846
+ type foo = _Foo # equivalent to _Foo[untyped]
847
+ type bar = _Bar[String] # equivalent to _Bar[String, untyped]
848
+ ```
849
+
850
+ Type parameters with default types cannot appear before type parameters without default types. The generic method type parameters cannot have the default types.
837
851
 
838
852
  ### Directives
839
853
 
@@ -116,7 +116,7 @@ token rbsparser_next_token(lexstate *state) {
116
116
  yy1:
117
117
  rbs_skip(state);
118
118
  #line 144 "ext/rbs_extension/lexer.re"
119
- { return next_token(state, pEOF); }
119
+ { return next_eof_token(state); }
120
120
  #line 121 "ext/rbs_extension/lexer.c"
121
121
  yy2:
122
122
  rbs_skip(state);
@@ -167,6 +167,11 @@ void skipn(lexstate *state, size_t size);
167
167
  * */
168
168
  token next_token(lexstate *state, enum TokenType type);
169
169
 
170
+ /**
171
+ * Return new token with EOF type.
172
+ * */
173
+ token next_eof_token(lexstate *state);
174
+
170
175
  token rbsparser_next_token(lexstate *state);
171
176
 
172
177
  void print_token(token tok);
@@ -141,7 +141,7 @@ token rbsparser_next_token(lexstate *state) {
141
141
  skip = ([ \t]+|[\r\n]);
142
142
 
143
143
  skip { return next_token(state, tTRIVIA); }
144
- "\x00" { return next_token(state, pEOF); }
144
+ "\x00" { return next_eof_token(state); }
145
145
  * { return next_token(state, ErrorToken); }
146
146
  */
147
147
  }
@@ -129,6 +129,22 @@ token next_token(lexstate *state, enum TokenType type) {
129
129
  return t;
130
130
  }
131
131
 
132
+ token next_eof_token(lexstate *state) {
133
+ if (state->current.byte_pos == RSTRING_LEN(state->string)+1) {
134
+ // End of String
135
+ token t;
136
+ t.type = pEOF;
137
+ t.range.start = state->start;
138
+ t.range.end = state->start;
139
+ state->start = state->current;
140
+
141
+ return t;
142
+ } else {
143
+ // NULL byte in the middle of the string
144
+ return next_token(state, pEOF);
145
+ }
146
+ }
147
+
132
148
  void rbs_skip(lexstate *state) {
133
149
  if (!state->last_char) {
134
150
  peek(state);
@@ -3,7 +3,9 @@
3
3
  #define RBS_LOC_REQUIRED_P(loc, i) ((loc)->children->required_p & (1 << (i)))
4
4
  #define RBS_LOC_OPTIONAL_P(loc, i) (!RBS_LOC_REQUIRED_P((loc), (i)))
5
5
  #define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1))
6
+ #define NULL_LOC_RANGE_P(rg) ((rg).start == -1)
6
7
 
8
+ rbs_loc_range RBS_LOC_NULL_RANGE = { -1, -1 };
7
9
  VALUE RBS_Location;
8
10
 
9
11
  position rbs_loc_position(int char_pos) {
@@ -16,6 +18,11 @@ position rbs_loc_position3(int char_pos, int line, int column) {
16
18
  return pos;
17
19
  }
18
20
 
21
+ rbs_loc_range rbs_new_loc_range(range rg) {
22
+ rbs_loc_range r = { rg.start.char_pos, rg.end.char_pos };
23
+ return r;
24
+ }
25
+
19
26
  static void check_children_max(unsigned short n) {
20
27
  size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
21
28
  if (n > max) {
@@ -51,7 +58,7 @@ void rbs_loc_add_required_child(rbs_loc *loc, ID name, range r) {
51
58
 
52
59
  unsigned short i = loc->children->len++;
53
60
  loc->children->entries[i].name = name;
54
- loc->children->entries[i].rg = r;
61
+ loc->children->entries[i].rg = rbs_new_loc_range(r);
55
62
 
56
63
  loc->children->required_p |= 1 << i;
57
64
  }
@@ -61,10 +68,10 @@ void rbs_loc_add_optional_child(rbs_loc *loc, ID name, range r) {
61
68
 
62
69
  unsigned short i = loc->children->len++;
63
70
  loc->children->entries[i].name = name;
64
- loc->children->entries[i].rg = r;
71
+ loc->children->entries[i].rg = rbs_new_loc_range(r);
65
72
  }
66
73
 
67
- void rbs_loc_init(rbs_loc *loc, VALUE buffer, range rg) {
74
+ void rbs_loc_init(rbs_loc *loc, VALUE buffer, rbs_loc_range rg) {
68
75
  loc->buffer = buffer;
69
76
  loc->rg = rg;
70
77
  loc->children = NULL;
@@ -100,7 +107,7 @@ static VALUE location_s_allocate(VALUE klass) {
100
107
  rbs_loc *loc;
101
108
  VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
102
109
 
103
- rbs_loc_init(loc, Qnil, NULL_RANGE);
110
+ rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
104
111
 
105
112
  return obj;
106
113
  }
@@ -112,8 +119,8 @@ rbs_loc *rbs_check_location(VALUE obj) {
112
119
  static VALUE location_initialize(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
113
120
  rbs_loc *loc = rbs_check_location(self);
114
121
 
115
- position start = rbs_loc_position(FIX2INT(start_pos));
116
- position end = rbs_loc_position(FIX2INT(end_pos));
122
+ int start = FIX2INT(start_pos);
123
+ int end = FIX2INT(end_pos);
117
124
 
118
125
  loc->buffer = buffer;
119
126
  loc->rg.start = start;
@@ -143,38 +150,12 @@ static VALUE location_buffer(VALUE self) {
143
150
 
144
151
  static VALUE location_start_pos(VALUE self) {
145
152
  rbs_loc *loc = rbs_check_location(self);
146
- return INT2FIX(loc->rg.start.char_pos);
153
+ return INT2FIX(loc->rg.start);
147
154
  }
148
155
 
149
156
  static VALUE location_end_pos(VALUE self) {
150
157
  rbs_loc *loc = rbs_check_location(self);
151
- return INT2FIX(loc->rg.end.char_pos);
152
- }
153
-
154
- static VALUE location_start_loc(VALUE self) {
155
- rbs_loc *loc = rbs_check_location(self);
156
-
157
- if (loc->rg.start.line >= 0) {
158
- VALUE pair = rb_ary_new_capa(2);
159
- rb_ary_push(pair, INT2FIX(loc->rg.start.line));
160
- rb_ary_push(pair, INT2FIX(loc->rg.start.column));
161
- return pair;
162
- } else {
163
- return Qnil;
164
- }
165
- }
166
-
167
- static VALUE location_end_loc(VALUE self) {
168
- rbs_loc *loc = rbs_check_location(self);
169
-
170
- if (loc->rg.end.line >= 0) {
171
- VALUE pair = rb_ary_new_capa(2);
172
- rb_ary_push(pair, INT2FIX(loc->rg.end.line));
173
- rb_ary_push(pair, INT2FIX(loc->rg.end.column));
174
- return pair;
175
- } else {
176
- return Qnil;
177
- }
158
+ return INT2FIX(loc->rg.end);
178
159
  }
179
160
 
180
161
  static VALUE location_add_required_child(VALUE self, VALUE name, VALUE start, VALUE end) {
@@ -213,6 +194,15 @@ VALUE rbs_new_location(VALUE buffer, range rg) {
213
194
  rbs_loc *loc;
214
195
  VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
215
196
 
197
+ rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
198
+
199
+ return obj;
200
+ }
201
+
202
+ static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
203
+ rbs_loc *loc;
204
+ VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
205
+
216
206
  rbs_loc_init(loc, buffer, rg);
217
207
 
218
208
  return obj;
@@ -226,12 +216,12 @@ static VALUE location_aref(VALUE self, VALUE name) {
226
216
  if (loc->children != NULL) {
227
217
  for (unsigned short i = 0; i < loc->children->len; i++) {
228
218
  if (loc->children->entries[i].name == id) {
229
- range result = loc->children->entries[i].rg;
219
+ rbs_loc_range result = loc->children->entries[i].rg;
230
220
 
231
- if (RBS_LOC_OPTIONAL_P(loc, i) && null_range_p(result)) {
221
+ if (RBS_LOC_OPTIONAL_P(loc, i) && NULL_LOC_RANGE_P(result)) {
232
222
  return Qnil;
233
223
  } else {
234
- return rbs_new_location(loc->buffer, result);
224
+ return rbs_new_location_from_loc_range(loc->buffer, result);
235
225
  }
236
226
  }
237
227
  }
@@ -294,8 +284,6 @@ void rbs__init_location(void) {
294
284
  rb_define_method(RBS_Location, "buffer", location_buffer, 0);
295
285
  rb_define_method(RBS_Location, "start_pos", location_start_pos, 0);
296
286
  rb_define_method(RBS_Location, "end_pos", location_end_pos, 0);
297
- rb_define_private_method(RBS_Location, "_start_loc", location_start_loc, 0);
298
- rb_define_private_method(RBS_Location, "_end_loc", location_end_loc, 0);
299
287
  rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3);
300
288
  rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3);
301
289
  rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1);
@@ -9,9 +9,14 @@
9
9
  * */
10
10
  extern VALUE RBS_Location;
11
11
 
12
+ typedef struct {
13
+ int start;
14
+ int end;
15
+ } rbs_loc_range;
16
+
12
17
  typedef struct {
13
18
  ID name;
14
- range rg;
19
+ rbs_loc_range rg;
15
20
  } rbs_loc_entry;
16
21
 
17
22
  typedef unsigned int rbs_loc_entry_bitmap;
@@ -27,7 +32,7 @@ typedef struct {
27
32
 
28
33
  typedef struct {
29
34
  VALUE buffer;
30
- range rg;
35
+ rbs_loc_range rg;
31
36
  rbs_loc_children *children; // NULL when no children is allocated
32
37
  } rbs_loc;
33
38