rbs 1.7.0.beta.4 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/CHANGELOG.md +58 -2
  4. data/Steepfile +0 -1
  5. data/core/array.rbs +3 -3
  6. data/core/binding.rbs +2 -0
  7. data/core/builtin.rbs +4 -0
  8. data/core/complex.rbs +0 -2
  9. data/core/enumerable.rbs +3 -3
  10. data/core/env.rbs +881 -0
  11. data/core/false_class.rbs +2 -0
  12. data/core/float.rbs +0 -2
  13. data/core/integer.rbs +0 -2
  14. data/core/nil_class.rbs +2 -0
  15. data/core/numeric.rbs +7 -0
  16. data/core/object.rbs +1 -1
  17. data/core/proc.rbs +2 -0
  18. data/core/rational.rbs +0 -2
  19. data/core/symbol.rbs +2 -0
  20. data/core/thread.rbs +1 -1
  21. data/core/true_class.rbs +2 -0
  22. data/core/unbound_method.rbs +13 -0
  23. data/docs/rbs_by_example.md +2 -2
  24. data/docs/syntax.md +25 -23
  25. data/ext/rbs_extension/parser.c +99 -95
  26. data/ext/rbs_extension/parserstate.c +0 -1
  27. data/ext/rbs_extension/rbs_extension.h +1 -1
  28. data/ext/rbs_extension/ruby_objs.c +8 -6
  29. data/ext/rbs_extension/ruby_objs.h +2 -4
  30. data/lib/rbs/ast/declarations.rb +6 -2
  31. data/lib/rbs/cli.rb +1 -1
  32. data/lib/rbs/collection/sources/git.rb +6 -1
  33. data/lib/rbs/definition_builder.rb +29 -2
  34. data/lib/rbs/environment.rb +1 -0
  35. data/lib/rbs/environment_walker.rb +4 -1
  36. data/lib/rbs/errors.rb +12 -0
  37. data/lib/rbs/prototype/helpers.rb +113 -0
  38. data/lib/rbs/prototype/rb.rb +2 -105
  39. data/lib/rbs/prototype/runtime.rb +16 -0
  40. data/lib/rbs/test/setup.rb +1 -0
  41. data/lib/rbs/type_alias_regularity.rb +115 -0
  42. data/lib/rbs/types.rb +11 -23
  43. data/lib/rbs/validator.rb +40 -7
  44. data/lib/rbs/variance_calculator.rb +52 -24
  45. data/lib/rbs/version.rb +1 -1
  46. data/lib/rbs/writer.rb +1 -1
  47. data/lib/rbs.rb +2 -0
  48. data/schema/decls.json +13 -1
  49. data/schema/types.json +8 -2
  50. data/sig/collection/collections.rbs +2 -0
  51. data/sig/declarations.rbs +9 -6
  52. data/sig/definition_builder.rbs +29 -0
  53. data/sig/environment_walker.rbs +26 -0
  54. data/sig/errors.rbs +10 -0
  55. data/sig/type_alias_regularity.rbs +92 -0
  56. data/sig/types.rbs +11 -8
  57. data/sig/validator.rbs +7 -0
  58. data/sig/variance_calculator.rbs +50 -0
  59. data/stdlib/bigdecimal/0/big_decimal.rbs +44 -0
  60. data/stdlib/csv/0/csv.rbs +49 -3
  61. data/stdlib/date/0/date.rbs +2 -2
  62. data/stdlib/set/0/set.rbs +3 -3
  63. data/steep/Gemfile.lock +10 -10
  64. metadata +8 -6
  65. data/lib/rbs/parser.y +0 -1805
  66. data/lib/ruby/signature.rb +0 -7
data/core/false_class.rbs CHANGED
@@ -37,4 +37,6 @@ class FalseClass
37
37
  def |: (nil) -> false
38
38
  | (false) -> false
39
39
  | (untyped obj) -> true
40
+
41
+ def clone: (?freeze: true?) -> self
40
42
  end
data/core/float.rbs CHANGED
@@ -171,8 +171,6 @@ class Float < Numeric
171
171
  def ceil: () -> Integer
172
172
  | (int digits) -> (Integer | Float)
173
173
 
174
- def clone: (?freeze: bool) -> self
175
-
176
174
  # Returns an array with both `numeric` and `float` represented as Float objects.
177
175
  #
178
176
  # This is achieved by converting `numeric` to a Float.
data/core/integer.rbs CHANGED
@@ -272,8 +272,6 @@ class Integer < Numeric
272
272
  #
273
273
  def chr: (?encoding) -> String
274
274
 
275
- def clone: (?freeze: bool) -> self
276
-
277
275
  # Returns an array with both a `numeric` and a `big` represented as Bignum
278
276
  # objects.
279
277
  #
data/core/nil_class.rbs CHANGED
@@ -79,4 +79,6 @@ class NilClass
79
79
  def |: (nil) -> false
80
80
  | (false) -> false
81
81
  | (untyped obj) -> bool
82
+
83
+ def clone: (?freeze: true?) -> self
82
84
  end
data/core/numeric.rbs CHANGED
@@ -416,4 +416,11 @@ class Numeric
416
416
  # Returns `true` if `num` has a zero value.
417
417
  #
418
418
  def zero?: () -> bool
419
+
420
+ # Returns +self+.
421
+ #
422
+ # Raises an exception if the value for +freeze+ is neither +true+ nor +nil+.
423
+ #
424
+ # Related: Numeric#dup.
425
+ def clone: (?freeze: true?) -> self
419
426
  end
data/core/object.rbs CHANGED
@@ -76,7 +76,7 @@ class Object < BasicObject
76
76
  # This method may have class-specific behavior. If so, that behavior will be
77
77
  # documented under the #`initialize_copy` method of the class.
78
78
  #
79
- def clone: (?freeze: bool) -> self
79
+ def clone: (?freeze: bool?) -> self
80
80
 
81
81
  # Defines a singleton method in the receiver. The *method* parameter can be a
82
82
  # `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified, it
data/core/proc.rbs CHANGED
@@ -210,6 +210,8 @@
210
210
  # {test: 1}.to_proc.call(:test) #=> 1
211
211
  # %i[test many keys].map(&{test: 1}) #=> [1, nil, nil]
212
212
  class Proc < Object
213
+ def clone: () -> self
214
+
213
215
  # Returns the number of mandatory arguments. If the block is declared to
214
216
  # take no arguments, returns 0. If the block is known to take exactly n
215
217
  # arguments, returns n. If the block has optional arguments, returns -n-1,
data/core/rational.rbs CHANGED
@@ -175,8 +175,6 @@ class Rational < Numeric
175
175
  def ceil: () -> Integer
176
176
  | (Integer digits) -> (Integer | Rational)
177
177
 
178
- def clone: (?freeze: bool) -> self
179
-
180
178
  def coerce: (Numeric) -> [Numeric, Numeric]
181
179
 
182
180
  def conj: () -> Rational
data/core/symbol.rbs CHANGED
@@ -226,4 +226,6 @@ class Symbol
226
226
  | (:ascii | :lithuanian | :turkic) -> Symbol
227
227
  | (:lithuanian, :turkic) -> Symbol
228
228
  | (:turkic, :lithuanian) -> Symbol
229
+
230
+ def clone: (?freeze: true?) -> self
229
231
  end
data/core/thread.rbs CHANGED
@@ -554,7 +554,7 @@ class Thread < Object
554
554
  # b = Thread.new { raise 'something went wrong' }
555
555
  # b.value #=> RuntimeError: something went wrong
556
556
  # ```
557
- def value: () -> Object
557
+ def value: () -> untyped
558
558
 
559
559
  # Marks a given thread as eligible for scheduling, however it may still
560
560
  # remain blocked on I/O.
data/core/true_class.rbs CHANGED
@@ -43,4 +43,6 @@ class TrueClass
43
43
  # or
44
44
  #
45
45
  def |: (untyped obj) -> true
46
+
47
+ def clone: (?freeze: true?) -> self
46
48
  end
@@ -45,6 +45,19 @@
45
45
  # um.bind(t).call #=> :original
46
46
  #
47
47
  class UnboundMethod
48
+ # Returns a clone of this method.
49
+ #
50
+ # class A
51
+ # def foo
52
+ # return "bar"
53
+ # end
54
+ # end
55
+ #
56
+ # m = A.new.method(:foo)
57
+ # m.call # => "bar"
58
+ # n = m.clone.call # => "bar"
59
+ def clone: () -> self
60
+
48
61
  # Returns an indication of the number of arguments accepted by a method. Returns
49
62
  # a nonnegative integer for methods that take a fixed number of arguments. For
50
63
  # Ruby methods that take a variable number of arguments, returns -n-1, where n
@@ -229,9 +229,9 @@ end
229
229
 
230
230
  ```ruby
231
231
  # .rb
232
- [1,2,3,4,5].select {|num| num.even? }
232
+ [1,2,3,4,5].filter {|num| num.even? }
233
233
  # => [2, 4]
234
- %w[ a b c d e f ].select {|v| v =~ /[aeiou]/ }
234
+ %w[ a b c d e f ].filter {|v| v =~ /[aeiou]/ }
235
235
  # => ["a", "e"]
236
236
  [1,2,3,4,5].filter
237
237
  ```
data/docs/syntax.md CHANGED
@@ -5,14 +5,14 @@
5
5
  ```markdown
6
6
  _type_ ::= _class-name_ _type-arguments_ (Class instance type)
7
7
  | _interface-name_ _type-arguments_ (Interface type)
8
+ | _alias-name_ _type-arguments_ (Alias type)
8
9
  | `singleton(` _class-name_ `)` (Class singleton type)
9
- | _alias-name_ (Alias type)
10
10
  | _literal_ (Literal type)
11
11
  | _type_ `|` _type_ (Union type)
12
12
  | _type_ `&` _type_ (Intersection type)
13
13
  | _type_ `?` (Optional type)
14
- | `{` _record-name_ `:` _type_ `,` etc. `}` (Record type)
15
- | `[]` | `[` _type_ `,` etc. `]` (Tuples)
14
+ | `{` _record-name_ `:` _type_ `,` etc. `}` (Record type)
15
+ | `[]` | `[` _type_ `,` etc. `]` (Tuples)
16
16
  | _type-variable_ (Type variables)
17
17
  | `^(` _parameters_ `) ->` _type_ (Proc type)
18
18
  | `self`
@@ -35,8 +35,8 @@ _namespace_ ::= (Empty namespace)
35
35
  | `::` (Root)
36
36
  | _namespace_ /[A-Z]\w*/ `::` (Namespace)
37
37
 
38
- _type-arguments_ ::= (No application)
39
- | `[` _type_ `,` etc. `]` (Type application)
38
+ _type-arguments_ ::= (No type arguments)
39
+ | `[` _type_ `,` etc. `]` (Type arguments)
40
40
 
41
41
  _literal_ ::= _string-literal_
42
42
  | _symbol-literal_
@@ -64,25 +64,25 @@ _ToS # _ToS interface
64
64
  ::MyApp::_Each[String] # Interface name with namespace and type application
65
65
  ```
66
66
 
67
- ### Class singleton type
68
-
69
- Class singleton type denotes _the type of a singleton object of a class_.
70
-
71
- ```
72
- singleton(String)
73
- singleton(::Hash) # Class singleton type cannot be parametrized.
74
- ```
75
-
76
67
  ### Alias type
77
68
 
78
69
  Alias type denotes an alias declared with _alias declaration_.
79
70
 
80
71
  The name of type aliases starts with lowercase `[a-z]`.
81
72
 
82
-
83
73
  ```
84
74
  name
85
75
  ::JSON::t # Alias name with namespace
76
+ list[Integer] # Type alias can be generic
77
+ ```
78
+
79
+ ### Class singleton type
80
+
81
+ Class singleton type denotes _the type of a singleton object of a class_.
82
+
83
+ ```
84
+ singleton(String)
85
+ singleton(::Hash) # Class singleton type cannot be parametrized.
86
86
  ```
87
87
 
88
88
  ### Literal type
@@ -110,10 +110,10 @@ Array[Integer | String] # Array of Integer or String
110
110
  Intersection type denotes _a type of all of the given types_.
111
111
 
112
112
  ```
113
- Integer & String # Integer and String
113
+ _Reader & _Writer # _Reader and _Writer
114
114
  ```
115
115
 
116
- Note that `&` has higher precedence than `|` that `Integer & String | Symbol` is `(Integer & String) | Symbol`.
116
+ Note that `&` has higher precedence than `|` that `A & B | C` is `(A & B) | C`.
117
117
 
118
118
  ### Optional type
119
119
 
@@ -155,7 +155,7 @@ Elem
155
155
  ```
156
156
 
157
157
  Type variables cannot be distinguished from _class instance types_.
158
- They are scoped in _class/module/interface declaration_ or _generic method types_.
158
+ They are scoped in _class/module/interface/alias declaration_ or _generic method types_.
159
159
 
160
160
  ```
161
161
  class Ref[T] # Object is scoped in the class declaration.
@@ -289,7 +289,6 @@ _method-member_ ::= `def` _method-name_ `:` _method-types_ # Instance
289
289
  | `def self?.` _method-name_ `:` _method-types_ # Singleton and instance method
290
290
 
291
291
  _method-types_ ::= # Empty
292
- | `super` # `super` overloading
293
292
  | _type-parameters_ _method-type_ `|` _method-types_ # Overloading types
294
293
  | `...` # Overloading for duplicate definitions
295
294
 
@@ -415,7 +414,6 @@ These work only as _statements_, not per-method specifier.
415
414
  _decl_ ::= _class-decl_ # Class declaration
416
415
  | _module-decl_ # Module declaration
417
416
  | _interface-decl_ # Interface declaration
418
- | _extension-decl_ # Extension declaration
419
417
  | _type-alias-decl_ # Type alias declaration
420
418
  | _const-decl_ # Constant declaration
421
419
  | _global-decl_ # Global declaration
@@ -435,9 +433,7 @@ _interface-members_ ::= _method-member_ # Method
435
433
  | _include-member_ # Mixin (include)
436
434
  | _alias-member_ # Alias
437
435
 
438
- _extension-decl_ ::= `extension` _class-name_ _type-parameters_ `(` _extension-name_ `)` _members_ `end`
439
-
440
- _type-alias-decl_ ::= `type` _alias-name_ `=` _type_
436
+ _type-alias-decl_ ::= `type` _alias-name_ _module-type-parameters_ `=` _type_
441
437
 
442
438
  _const-decl_ ::= _const-name_ `:` _type_
443
439
 
@@ -537,6 +533,12 @@ type subject = Attendee | Speaker
537
533
  type JSON::t = Integer | TrueClass | FalseClass | String | Hash[Symbol, t] | Array[t]
538
534
  ```
539
535
 
536
+ Type alias can be generic like class, module, and interface.
537
+
538
+ ```
539
+ type list[out T] = [T, list[T]] | nil
540
+ ```
541
+
540
542
  ### Constant type declaration
541
543
 
542
544
  You can declare a constant.
@@ -273,7 +273,7 @@ static VALUE parse_function_param(parserstate *state) {
273
273
  param_range.start = type_range.start;
274
274
  param_range.end = name_range.end;
275
275
 
276
- VALUE name = ID2SYM(INTERN_TOKEN(state, state->current_token));
276
+ VALUE name = rb_to_symbol(rbs_unquote_string(state, state->current_token.range, 0));
277
277
  VALUE location = rbs_new_location(state->buffer, param_range);
278
278
  rbs_loc *loc = rbs_check_location(location);
279
279
  rbs_loc_add_optional_child(loc, rb_intern("name"), name_range);
@@ -815,6 +815,8 @@ static VALUE parse_simple(parserstate *state) {
815
815
  }
816
816
  case tULIDENT:
817
817
  // fallthrough
818
+ case tLIDENT:
819
+ // fallthrough
818
820
  case pCOLON2: {
819
821
  range name_range;
820
822
  range args_range;
@@ -857,19 +859,11 @@ static VALUE parse_simple(parserstate *state) {
857
859
  } else if (kind == INTERFACE_NAME) {
858
860
  return rbs_interface(typename, types, location);
859
861
  } else if (kind == ALIAS_NAME) {
860
- return rbs_alias(typename, location);
862
+ return rbs_alias(typename, types, location);
861
863
  } else {
862
864
  return Qnil;
863
865
  }
864
866
  }
865
- case tLIDENT: {
866
- VALUE location = rbs_location_current_token(state);
867
- rbs_loc *loc = rbs_check_location(location);
868
- rbs_loc_add_required_child(loc, rb_intern("name"), state->current_token.range);
869
- rbs_loc_add_optional_child(loc, rb_intern("args"), NULL_RANGE);
870
- VALUE typename = parse_type_name(state, ALIAS_NAME, NULL);
871
- return rbs_alias(typename, location);
872
- }
873
867
  case kSINGLETON: {
874
868
  range name_range;
875
869
  range type_range;
@@ -1093,12 +1087,98 @@ VALUE parse_const_decl(parserstate *state) {
1093
1087
  return rbs_ast_decl_constant(typename, type, location, comment);
1094
1088
  }
1095
1089
 
1090
+ /*
1091
+ module_type_params ::= {} `[` module_type_param `,` ... <`]`>
1092
+ | {<>}
1093
+
1094
+ module_type_param ::= kUNCHECKED? (kIN|kOUT|) tUIDENT
1095
+ */
1096
+ VALUE parse_module_type_params(parserstate *state, range *rg) {
1097
+ VALUE params = rbs_ast_decl_module_type_params();
1098
+
1099
+ if (state->next_token.type == pLBRACKET) {
1100
+ parser_advance(state);
1101
+
1102
+ rg->start = state->current_token.range.start;
1103
+
1104
+ while (true) {
1105
+ VALUE name;
1106
+ VALUE unchecked = Qfalse;
1107
+ VALUE variance = ID2SYM(rb_intern("invariant"));
1108
+
1109
+ range param_range = NULL_RANGE;
1110
+ range name_range;
1111
+ range variance_range = NULL_RANGE;
1112
+ range unchecked_range = NULL_RANGE;
1113
+
1114
+ param_range.start = state->next_token.range.start;
1115
+
1116
+ if (state->next_token.type == kUNCHECKED) {
1117
+ unchecked = Qtrue;
1118
+ parser_advance(state);
1119
+ unchecked_range = state->current_token.range;
1120
+ }
1121
+
1122
+ if (state->next_token.type == kIN || state->next_token.type == kOUT) {
1123
+ switch (state->next_token.type) {
1124
+ case kIN:
1125
+ variance = ID2SYM(rb_intern("contravariant"));
1126
+ break;
1127
+ case kOUT:
1128
+ variance = ID2SYM(rb_intern("covariant"));
1129
+ break;
1130
+ default:
1131
+ rbs_abort();
1132
+ }
1133
+
1134
+ parser_advance(state);
1135
+ variance_range = state->current_token.range;
1136
+ }
1137
+
1138
+ parser_advance_assert(state, tUIDENT);
1139
+ name_range = state->current_token.range;
1140
+ param_range.end = state->current_token.range.end;
1141
+
1142
+ ID id = INTERN_TOKEN(state, state->current_token);
1143
+ name = ID2SYM(id);
1144
+
1145
+ parser_insert_typevar(state, id);
1146
+
1147
+ VALUE location = rbs_new_location(state->buffer, param_range);
1148
+ rbs_loc *loc = rbs_check_location(location);
1149
+ rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1150
+ rbs_loc_add_optional_child(loc, rb_intern("variance"), variance_range);
1151
+ rbs_loc_add_optional_child(loc, rb_intern("unchecked"), unchecked_range);
1152
+
1153
+ VALUE param = rbs_ast_decl_module_type_params_param(name, variance, unchecked, location);
1154
+ rb_funcall(params, rb_intern("add"), 1, param);
1155
+
1156
+ if (state->next_token.type == pCOMMA) {
1157
+ parser_advance(state);
1158
+ }
1159
+
1160
+ if (state->next_token.type == pRBRACKET) {
1161
+ break;
1162
+ }
1163
+ }
1164
+
1165
+ parser_advance_assert(state, pRBRACKET);
1166
+ rg->end = state->current_token.range.end;
1167
+ } else {
1168
+ *rg = NULL_RANGE;
1169
+ }
1170
+
1171
+ return params;
1172
+ }
1173
+
1096
1174
  /*
1097
1175
  type_decl ::= {kTYPE} alias_name `=` <type>
1098
1176
  */
1099
1177
  VALUE parse_type_decl(parserstate *state, position comment_pos, VALUE annotations) {
1100
1178
  range decl_range;
1101
- range keyword_range, name_range, eq_range;
1179
+ range keyword_range, name_range, params_range, eq_range;
1180
+
1181
+ parser_push_typevar_table(state, true);
1102
1182
 
1103
1183
  decl_range.start = state->current_token.range.start;
1104
1184
  comment_pos = nonnull_pos_or(comment_pos, decl_range.start);
@@ -1108,6 +1188,8 @@ VALUE parse_type_decl(parserstate *state, position comment_pos, VALUE annotation
1108
1188
  parser_advance(state);
1109
1189
  VALUE typename = parse_type_name(state, ALIAS_NAME, &name_range);
1110
1190
 
1191
+ VALUE type_params = parse_module_type_params(state, &params_range);
1192
+
1111
1193
  parser_advance_assert(state, pEQ);
1112
1194
  eq_range = state->current_token.range;
1113
1195
 
@@ -1118,10 +1200,14 @@ VALUE parse_type_decl(parserstate *state, position comment_pos, VALUE annotation
1118
1200
  rbs_loc *loc = rbs_check_location(location);
1119
1201
  rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
1120
1202
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1203
+ rbs_loc_add_optional_child(loc, rb_intern("type_params"), params_range);
1121
1204
  rbs_loc_add_required_child(loc, rb_intern("eq"), eq_range);
1122
1205
 
1206
+ parser_pop_typevar_table(state);
1207
+
1123
1208
  return rbs_ast_decl_alias(
1124
1209
  typename,
1210
+ type_params,
1125
1211
  type,
1126
1212
  annotations,
1127
1213
  location,
@@ -1184,90 +1270,6 @@ VALUE parse_annotation(parserstate *state) {
1184
1270
  return rbs_ast_annotation(string, location);
1185
1271
  }
1186
1272
 
1187
- /*
1188
- module_type_params ::= {} `[` module_type_param `,` ... <`]`>
1189
- | {<>}
1190
-
1191
- module_type_param ::= kUNCHECKED? (kIN|kOUT|) tUIDENT
1192
- */
1193
- VALUE parse_module_type_params(parserstate *state, range *rg) {
1194
- VALUE params = rbs_ast_decl_module_type_params();
1195
-
1196
- if (state->next_token.type == pLBRACKET) {
1197
- parser_advance(state);
1198
-
1199
- rg->start = state->current_token.range.start;
1200
-
1201
- while (true) {
1202
- VALUE name;
1203
- VALUE unchecked = Qfalse;
1204
- VALUE variance = ID2SYM(rb_intern("invariant"));
1205
-
1206
- range param_range = NULL_RANGE;
1207
- range name_range;
1208
- range variance_range = NULL_RANGE;
1209
- range unchecked_range = NULL_RANGE;
1210
-
1211
- param_range.start = state->next_token.range.start;
1212
-
1213
- if (state->next_token.type == kUNCHECKED) {
1214
- unchecked = Qtrue;
1215
- parser_advance(state);
1216
- unchecked_range = state->current_token.range;
1217
- }
1218
-
1219
- if (state->next_token.type == kIN || state->next_token.type == kOUT) {
1220
- switch (state->next_token.type) {
1221
- case kIN:
1222
- variance = ID2SYM(rb_intern("contravariant"));
1223
- break;
1224
- case kOUT:
1225
- variance = ID2SYM(rb_intern("covariant"));
1226
- break;
1227
- default:
1228
- rbs_abort();
1229
- }
1230
-
1231
- parser_advance(state);
1232
- variance_range = state->current_token.range;
1233
- }
1234
-
1235
- parser_advance_assert(state, tUIDENT);
1236
- name_range = state->current_token.range;
1237
- param_range.end = state->current_token.range.end;
1238
-
1239
- ID id = INTERN_TOKEN(state, state->current_token);
1240
- name = ID2SYM(id);
1241
-
1242
- parser_insert_typevar(state, id);
1243
-
1244
- VALUE location = rbs_new_location(state->buffer, param_range);
1245
- rbs_loc *loc = rbs_check_location(location);
1246
- rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1247
- rbs_loc_add_optional_child(loc, rb_intern("variance"), variance_range);
1248
- rbs_loc_add_optional_child(loc, rb_intern("unchecked"), unchecked_range);
1249
-
1250
- VALUE param = rbs_ast_decl_module_type_params_param(name, variance, unchecked, location);
1251
- rb_funcall(params, rb_intern("add"), 1, param);
1252
-
1253
- if (state->next_token.type == pCOMMA) {
1254
- parser_advance(state);
1255
- }
1256
-
1257
- if (state->next_token.type == pRBRACKET) {
1258
- break;
1259
- }
1260
- }
1261
-
1262
- parser_advance_assert(state, pRBRACKET);
1263
- rg->end = state->current_token.range.end;
1264
- } else {
1265
- *rg = NULL_RANGE;
1266
- }
1267
-
1268
- return params;
1269
- }
1270
-
1271
1273
  /*
1272
1274
  annotations ::= {} annotation ... <annotation>
1273
1275
  | {<>}
@@ -1487,6 +1489,8 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
1487
1489
  case INSTANCE_SINGLETON_KIND:
1488
1490
  k = ID2SYM(rb_intern("singleton_instance"));
1489
1491
  break;
1492
+ default:
1493
+ rbs_abort();
1490
1494
  }
1491
1495
 
1492
1496
  VALUE location = rbs_new_location(state->buffer, member_range);
@@ -87,7 +87,6 @@ bool parser_typevar_member(parserstate *state, ID id) {
87
87
  }
88
88
 
89
89
  void print_parser(parserstate *state) {
90
- pp(state->buffer);
91
90
  printf(" current_token = %s (%d...%d)\n", token_type_str(state->current_token.type), state->current_token.range.start.char_pos, state->current_token.range.end.char_pos);
92
91
  printf(" next_token = %s (%d...%d)\n", token_type_str(state->next_token.type), state->next_token.range.start.char_pos, state->next_token.range.end.char_pos);
93
92
  printf(" next_token2 = %s (%d...%d)\n", token_type_str(state->next_token2.type), state->next_token2.range.start.char_pos, state->next_token2.range.end.char_pos);
@@ -37,4 +37,4 @@ VALUE rbs_unquote_string(parserstate *state, range rg, int offset_bytes);
37
37
  * foo.rbs:11:21...11:25: Syntax error: {message}, token=`{tok source}` ({tok type})
38
38
  * ```
39
39
  * */
40
- NORETURN(void) raise_syntax_error(parserstate *state, token tok, const char *fmt, ...);
40
+ PRINTF_ARGS(NORETURN(void) raise_syntax_error(parserstate *state, token tok, const char *fmt, ...), 3, 4);
@@ -70,15 +70,16 @@ VALUE rbs_class_singleton(VALUE typename, VALUE location) {
70
70
  );
71
71
  }
72
72
 
73
- VALUE rbs_alias(VALUE typename, VALUE location) {
74
- VALUE args = rb_hash_new();
75
- rb_hash_aset(args, ID2SYM(rb_intern("name")), typename);
76
- rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
73
+ VALUE rbs_alias(VALUE typename, VALUE args, VALUE location) {
74
+ VALUE kwargs = rb_hash_new();
75
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("name")), typename);
76
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("args")), args);
77
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("location")), location);
77
78
 
78
79
  return CLASS_NEW_INSTANCE(
79
80
  RBS_Types_Alias,
80
81
  1,
81
- &args
82
+ &kwargs
82
83
  );
83
84
  }
84
85
 
@@ -339,9 +340,10 @@ VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment)
339
340
  );
340
341
  }
341
342
 
342
- VALUE rbs_ast_decl_alias(VALUE name, VALUE type, VALUE annotations, VALUE location, VALUE comment) {
343
+ VALUE rbs_ast_decl_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment) {
343
344
  VALUE args = rb_hash_new();
344
345
  rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
346
+ rb_hash_aset(args, ID2SYM(rb_intern("type_params")), type_params);
345
347
  rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
346
348
  rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
347
349
  rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
@@ -3,10 +3,10 @@
3
3
 
4
4
  #include "ruby.h"
5
5
 
6
- VALUE rbs_alias(VALUE typename, VALUE location);
6
+ VALUE rbs_alias(VALUE typename, VALUE args, VALUE location);
7
7
  VALUE rbs_ast_annotation(VALUE string, VALUE location);
8
8
  VALUE rbs_ast_comment(VALUE string, VALUE location);
9
- VALUE rbs_ast_decl_alias(VALUE name, VALUE type, VALUE annotations, VALUE location, VALUE comment);
9
+ VALUE rbs_ast_decl_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
10
10
  VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
11
11
  VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
12
12
  VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment);
@@ -41,6 +41,4 @@ VALUE rbs_type_name(VALUE namespace, VALUE name);
41
41
  VALUE rbs_union(VALUE types, VALUE location);
42
42
  VALUE rbs_variable(VALUE name, VALUE location);
43
43
 
44
- void pp(VALUE object);
45
-
46
44
  #endif
@@ -362,13 +362,15 @@ module RBS
362
362
 
363
363
  class Alias < Base
364
364
  attr_reader :name
365
+ attr_reader :type_params
365
366
  attr_reader :type
366
367
  attr_reader :annotations
367
368
  attr_reader :location
368
369
  attr_reader :comment
369
370
 
370
- def initialize(name:, type:, annotations:, location:, comment:)
371
+ def initialize(name:, type_params:, type:, annotations:, location:, comment:)
371
372
  @name = name
373
+ @type_params = type_params
372
374
  @type = type
373
375
  @annotations = annotations
374
376
  @location = location
@@ -378,19 +380,21 @@ module RBS
378
380
  def ==(other)
379
381
  other.is_a?(Alias) &&
380
382
  other.name == name &&
383
+ other.type_params == type_params &&
381
384
  other.type == type
382
385
  end
383
386
 
384
387
  alias eql? ==
385
388
 
386
389
  def hash
387
- self.class.hash ^ name.hash ^ type.hash
390
+ self.class.hash ^ name.hash ^ type_params.hash ^ type.hash
388
391
  end
389
392
 
390
393
  def to_json(state = _ = nil)
391
394
  {
392
395
  declaration: :alias,
393
396
  name: name,
397
+ type_params: type_params,
394
398
  type: type,
395
399
  annotations: annotations,
396
400
  location: location,
data/lib/rbs/cli.rb CHANGED
@@ -460,7 +460,7 @@ EOU
460
460
 
461
461
  env.alias_decls.each do |name, decl|
462
462
  stdout.puts "Validating alias: `#{name}`..."
463
- builder.expand_alias(name).tap do |type|
463
+ builder.expand_alias1(name).tap do |type|
464
464
  validator.validate_type type, context: [Namespace.root]
465
465
  end
466
466
  validator.validate_type_alias(entry: decl)
@@ -102,7 +102,12 @@ module RBS
102
102
  git 'fetch', 'origin'
103
103
  end
104
104
  else
105
- git 'clone', remote, git_dir.to_s
105
+ begin
106
+ # git v2.27.0 or greater
107
+ git 'clone', '--filter=blob:none', remote, git_dir.to_s
108
+ rescue CommandError
109
+ git 'clone', remote, git_dir.to_s
110
+ end
106
111
  end
107
112
 
108
113
  begin