rbs 3.4.4 → 3.5.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +7 -0
- data/CHANGELOG.md +0 -26
- data/Gemfile +12 -1
- data/Gemfile.lock +51 -34
- data/README.md +2 -1
- data/Rakefile +2 -2
- data/core/enumerator.rbs +1 -1
- data/core/gc.rbs +272 -150
- data/core/integer.rbs +4 -3
- data/core/io/wait.rbs +4 -4
- data/core/io.rbs +10 -3
- data/core/kernel.rbs +8 -7
- data/core/module.rbs +17 -4
- data/core/range.rbs +2 -2
- data/core/regexp.rbs +101 -90
- data/core/ruby_vm.rbs +103 -103
- data/core/string.rbs +3 -3
- data/core/symbol.rbs +2 -1
- data/core/thread.rbs +1 -1
- data/core/time.rbs +24 -4
- data/docs/architecture.md +110 -0
- data/docs/syntax.md +5 -1
- data/ext/rbs_extension/constants.c +2 -0
- data/ext/rbs_extension/constants.h +1 -0
- data/ext/rbs_extension/location.c +79 -70
- data/ext/rbs_extension/location.h +23 -5
- data/ext/rbs_extension/parser.c +82 -24
- data/ext/rbs_extension/parserstate.c +4 -0
- data/ext/rbs_extension/ruby_objs.c +13 -3
- data/ext/rbs_extension/ruby_objs.h +1 -0
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +1 -6
- data/lib/rbs/definition_builder/method_builder.rb +1 -1
- data/lib/rbs/definition_builder.rb +8 -8
- data/lib/rbs/diff.rb +1 -1
- data/lib/rbs/environment_loader.rb +2 -1
- data/lib/rbs/errors.rb +0 -14
- data/lib/rbs/parser_aux.rb +0 -5
- data/lib/rbs/prototype/helpers.rb +22 -12
- data/lib/rbs/prototype/rb.rb +38 -4
- data/lib/rbs/prototype/rbi.rb +30 -20
- data/lib/rbs/test/errors.rb +19 -14
- data/lib/rbs/test/tester.rb +1 -1
- data/lib/rbs/test/type_check.rb +95 -16
- data/lib/rbs/types.rb +112 -13
- data/lib/rbs/unit_test/spy.rb +1 -1
- data/lib/rbs/version.rb +1 -1
- data/rbs.gemspec +1 -1
- data/sig/environment_loader.rbs +1 -1
- data/sig/errors.rbs +1 -1
- data/sig/method_types.rbs +3 -3
- data/sig/prototype/helpers.rbs +4 -0
- data/sig/prototype/rbi.rbs +2 -0
- data/sig/types.rbs +54 -4
- data/sig/variance_calculator.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +4 -1
- data/stdlib/fileutils/0/fileutils.rbs +1 -1
- data/stdlib/net-http/0/net-http.rbs +29 -27
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/timeout/0/timeout.rbs +6 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/uri/0/http.rbs +2 -2
- metadata +3 -6
- data/lib/rbs/parser_compat/lexer_error.rb +0 -6
- data/lib/rbs/parser_compat/located_value.rb +0 -7
- data/lib/rbs/parser_compat/semantics_error.rb +0 -6
- data/lib/rbs/parser_compat/syntax_error.rb +0 -6
data/ext/rbs_extension/parser.c
CHANGED
@@ -52,6 +52,10 @@ typedef struct {
|
|
52
52
|
VALUE rest_keywords;
|
53
53
|
} method_params;
|
54
54
|
|
55
|
+
static bool rbs_is_untyped_params(method_params *params) {
|
56
|
+
return NIL_P(params->required_positionals);
|
57
|
+
}
|
58
|
+
|
55
59
|
// /**
|
56
60
|
// * Returns RBS::Location object of `current_token` of a parser state.
|
57
61
|
// *
|
@@ -78,7 +82,7 @@ static VALUE string_of_loc(parserstate *state, position start, position end) {
|
|
78
82
|
}
|
79
83
|
|
80
84
|
/**
|
81
|
-
* Raises RuntimeError with "Unexpected error "
|
85
|
+
* Raises RuntimeError with "Unexpected error " message.
|
82
86
|
* */
|
83
87
|
static NORETURN(void) rbs_abort(void) {
|
84
88
|
rb_raise(
|
@@ -265,6 +269,7 @@ static VALUE parse_function_param(parserstate *state) {
|
|
265
269
|
|
266
270
|
VALUE location = rbs_new_location(state->buffer, param_range);
|
267
271
|
rbs_loc *loc = rbs_check_location(location);
|
272
|
+
rbs_loc_alloc_children(loc, 1);
|
268
273
|
rbs_loc_add_optional_child(loc, rb_intern("name"), NULL_RANGE);
|
269
274
|
|
270
275
|
return rbs_function_param(type, Qnil, location);
|
@@ -287,6 +292,7 @@ static VALUE parse_function_param(parserstate *state) {
|
|
287
292
|
VALUE name = rb_to_symbol(rbs_unquote_string(state, state->current_token.range, 0));
|
288
293
|
VALUE location = rbs_new_location(state->buffer, param_range);
|
289
294
|
rbs_loc *loc = rbs_check_location(location);
|
295
|
+
rbs_loc_alloc_children(loc, 1);
|
290
296
|
rbs_loc_add_optional_child(loc, rb_intern("name"), name_range);
|
291
297
|
|
292
298
|
return rbs_function_param(type, name, location);
|
@@ -360,6 +366,7 @@ static bool is_keyword(parserstate *state) {
|
|
360
366
|
|
361
367
|
/*
|
362
368
|
params ::= {} `)`
|
369
|
+
| {} `?` `)` -- Untyped function params (assign params.required = nil)
|
363
370
|
| <required_params> `)`
|
364
371
|
| <required_params> `,` `)`
|
365
372
|
|
@@ -387,6 +394,11 @@ static bool is_keyword(parserstate *state) {
|
|
387
394
|
| {} `**` <function_param>
|
388
395
|
*/
|
389
396
|
static void parse_params(parserstate *state, method_params *params) {
|
397
|
+
if (state->next_token.type == pQUESTION && state->next_token2.type == pRPAREN) {
|
398
|
+
params->required_positionals = Qnil;
|
399
|
+
parser_advance(state);
|
400
|
+
return;
|
401
|
+
}
|
390
402
|
if (state->next_token.type == pRPAREN) {
|
391
403
|
return;
|
392
404
|
}
|
@@ -611,6 +623,13 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block, VA
|
|
611
623
|
parser_advance_assert(state, pRPAREN);
|
612
624
|
}
|
613
625
|
|
626
|
+
// Untyped method parameter means it cannot have block
|
627
|
+
if (rbs_is_untyped_params(¶ms)) {
|
628
|
+
if (state->next_token.type != pARROW) {
|
629
|
+
raise_syntax_error(state, state->next_token2, "A method type with untyped method parameter cannot have block");
|
630
|
+
}
|
631
|
+
}
|
632
|
+
|
614
633
|
// Passing NULL to function_self_type means the function itself doesn't accept self type binding. (== method type)
|
615
634
|
if (function_self_type) {
|
616
635
|
*function_self_type = parse_self_type_binding(state);
|
@@ -639,8 +658,11 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block, VA
|
|
639
658
|
parser_advance_assert(state, pARROW);
|
640
659
|
VALUE block_return_type = parse_optional(state);
|
641
660
|
|
642
|
-
|
643
|
-
|
661
|
+
VALUE block_function = Qnil;
|
662
|
+
if (rbs_is_untyped_params(&block_params)) {
|
663
|
+
block_function = rbs_untyped_function(block_return_type);
|
664
|
+
} else {
|
665
|
+
block_function = rbs_function(
|
644
666
|
block_params.required_positionals,
|
645
667
|
block_params.optional_positionals,
|
646
668
|
block_params.rest_positionals,
|
@@ -649,10 +671,10 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block, VA
|
|
649
671
|
block_params.optional_keywords,
|
650
672
|
block_params.rest_keywords,
|
651
673
|
block_return_type
|
652
|
-
)
|
653
|
-
|
654
|
-
|
655
|
-
);
|
674
|
+
);
|
675
|
+
}
|
676
|
+
|
677
|
+
*block = rbs_block(block_function, required, block_self_type);
|
656
678
|
|
657
679
|
parser_advance_assert(state, pRBRACE);
|
658
680
|
}
|
@@ -660,16 +682,20 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block, VA
|
|
660
682
|
parser_advance_assert(state, pARROW);
|
661
683
|
VALUE type = parse_optional(state);
|
662
684
|
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
685
|
+
if (rbs_is_untyped_params(¶ms)) {
|
686
|
+
*function = rbs_untyped_function(type);
|
687
|
+
} else {
|
688
|
+
*function = rbs_function(
|
689
|
+
params.required_positionals,
|
690
|
+
params.optional_positionals,
|
691
|
+
params.rest_positionals,
|
692
|
+
params.trailing_positionals,
|
693
|
+
params.required_keywords,
|
694
|
+
params.optional_keywords,
|
695
|
+
params.rest_keywords,
|
696
|
+
type
|
697
|
+
);
|
698
|
+
}
|
673
699
|
}
|
674
700
|
|
675
701
|
/*
|
@@ -698,15 +724,22 @@ static VALUE parse_proc_type(parserstate *state) {
|
|
698
724
|
| {} literal_type `=>` <type>
|
699
725
|
*/
|
700
726
|
VALUE parse_record_attributes(parserstate *state) {
|
701
|
-
VALUE
|
727
|
+
VALUE fields = rb_hash_new();
|
702
728
|
|
703
729
|
if (state->next_token.type == pRBRACE) {
|
704
|
-
return
|
730
|
+
return fields;
|
705
731
|
}
|
706
732
|
|
707
733
|
while (true) {
|
708
|
-
VALUE key
|
709
|
-
|
734
|
+
VALUE key, type,
|
735
|
+
value = rb_ary_new(),
|
736
|
+
required = Qtrue;
|
737
|
+
|
738
|
+
if (state->next_token.type == pQUESTION) {
|
739
|
+
// { ?foo: type } syntax
|
740
|
+
required = Qfalse;
|
741
|
+
parser_advance(state);
|
742
|
+
}
|
710
743
|
|
711
744
|
if (is_keyword(state)) {
|
712
745
|
// { foo: type } syntax
|
@@ -735,7 +768,9 @@ VALUE parse_record_attributes(parserstate *state) {
|
|
735
768
|
parser_advance_assert(state, pFATARROW);
|
736
769
|
}
|
737
770
|
type = parse_type(state);
|
738
|
-
|
771
|
+
rb_ary_push(value, type);
|
772
|
+
rb_ary_push(value, required);
|
773
|
+
rb_hash_aset(fields, key, value);
|
739
774
|
|
740
775
|
if (parser_advance_if(state, pCOMMA)) {
|
741
776
|
if (state->next_token.type == pRBRACE) {
|
@@ -745,8 +780,7 @@ VALUE parse_record_attributes(parserstate *state) {
|
|
745
780
|
break;
|
746
781
|
}
|
747
782
|
}
|
748
|
-
|
749
|
-
return hash;
|
783
|
+
return fields;
|
750
784
|
}
|
751
785
|
|
752
786
|
/*
|
@@ -832,6 +866,7 @@ static VALUE parse_instance_type(parserstate *state, bool parse_alias) {
|
|
832
866
|
|
833
867
|
VALUE location = rbs_new_location(state->buffer, type_range);
|
834
868
|
rbs_loc *loc = rbs_check_location(location);
|
869
|
+
rbs_loc_alloc_children(loc, 2);
|
835
870
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
836
871
|
rbs_loc_add_optional_child(loc, rb_intern("args"), args_range);
|
837
872
|
|
@@ -866,6 +901,7 @@ static VALUE parse_singleton_type(parserstate *state) {
|
|
866
901
|
|
867
902
|
VALUE location = rbs_new_location(state->buffer, type_range);
|
868
903
|
rbs_loc *loc = rbs_check_location(location);
|
904
|
+
rbs_loc_alloc_children(loc, 1);
|
869
905
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
870
906
|
|
871
907
|
return rbs_class_singleton(typename, location);
|
@@ -1121,6 +1157,7 @@ VALUE parse_type_params(parserstate *state, range *rg, bool module_type_params)
|
|
1121
1157
|
|
1122
1158
|
VALUE location = rbs_new_location(state->buffer, param_range);
|
1123
1159
|
rbs_loc *loc = rbs_check_location(location);
|
1160
|
+
rbs_loc_alloc_children(loc, 4);
|
1124
1161
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1125
1162
|
rbs_loc_add_optional_child(loc, rb_intern("variance"), variance_range);
|
1126
1163
|
rbs_loc_add_optional_child(loc, rb_intern("unchecked"), unchecked_range);
|
@@ -1181,6 +1218,7 @@ VALUE parse_method_type(parserstate *state) {
|
|
1181
1218
|
|
1182
1219
|
VALUE location = rbs_new_location(state->buffer, rg);
|
1183
1220
|
rbs_loc *loc = rbs_check_location(location);
|
1221
|
+
rbs_loc_alloc_children(loc, 2);
|
1184
1222
|
rbs_loc_add_required_child(loc, rb_intern("type"), type_range);
|
1185
1223
|
rbs_loc_add_optional_child(loc, rb_intern("type_params"), params_range);
|
1186
1224
|
|
@@ -1220,6 +1258,7 @@ VALUE parse_global_decl(parserstate *state) {
|
|
1220
1258
|
|
1221
1259
|
location = rbs_new_location(state->buffer, decl_range);
|
1222
1260
|
loc = rbs_check_location(location);
|
1261
|
+
rbs_loc_alloc_children(loc, 2);
|
1223
1262
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1224
1263
|
rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
|
1225
1264
|
|
@@ -1253,6 +1292,7 @@ VALUE parse_const_decl(parserstate *state) {
|
|
1253
1292
|
|
1254
1293
|
location = rbs_new_location(state->buffer, decl_range);
|
1255
1294
|
loc = rbs_check_location(location);
|
1295
|
+
rbs_loc_alloc_children(loc, 2);
|
1256
1296
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1257
1297
|
rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
|
1258
1298
|
|
@@ -1286,6 +1326,7 @@ VALUE parse_type_decl(parserstate *state, position comment_pos, VALUE annotation
|
|
1286
1326
|
|
1287
1327
|
VALUE location = rbs_new_location(state->buffer, decl_range);
|
1288
1328
|
rbs_loc *loc = rbs_check_location(location);
|
1329
|
+
rbs_loc_alloc_children(loc, 4);
|
1289
1330
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
1290
1331
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1291
1332
|
rbs_loc_add_optional_child(loc, rb_intern("type_params"), params_range);
|
@@ -1627,6 +1668,7 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
1627
1668
|
|
1628
1669
|
VALUE location = rbs_new_location(state->buffer, member_range);
|
1629
1670
|
rbs_loc *loc = rbs_check_location(location);
|
1671
|
+
rbs_loc_alloc_children(loc, 5);
|
1630
1672
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
1631
1673
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1632
1674
|
rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
|
@@ -1731,6 +1773,7 @@ VALUE parse_mixin_member(parserstate *state, bool from_interface, position comme
|
|
1731
1773
|
|
1732
1774
|
VALUE location = rbs_new_location(state->buffer, member_range);
|
1733
1775
|
rbs_loc *loc = rbs_check_location(location);
|
1776
|
+
rbs_loc_alloc_children(loc, 3);
|
1734
1777
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1735
1778
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
1736
1779
|
rbs_loc_add_optional_child(loc, rb_intern("args"), args_range);
|
@@ -1794,6 +1837,7 @@ VALUE parse_alias_member(parserstate *state, bool instance_only, position commen
|
|
1794
1837
|
member_range.end = state->current_token.range.end;
|
1795
1838
|
VALUE location = rbs_new_location(state->buffer, member_range);
|
1796
1839
|
rbs_loc *loc = rbs_check_location(location);
|
1840
|
+
rbs_loc_alloc_children(loc, 5);
|
1797
1841
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
1798
1842
|
rbs_loc_add_required_child(loc, rb_intern("new_name"), new_name_range);
|
1799
1843
|
rbs_loc_add_required_child(loc, rb_intern("old_name"), old_name_range);
|
@@ -1897,6 +1941,7 @@ VALUE parse_variable_member(parserstate *state, position comment_pos, VALUE anno
|
|
1897
1941
|
|
1898
1942
|
location = rbs_new_location(state->buffer, member_range);
|
1899
1943
|
rbs_loc *loc = rbs_check_location(location);
|
1944
|
+
rbs_loc_alloc_children(loc, 3);
|
1900
1945
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1901
1946
|
rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
|
1902
1947
|
rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
|
@@ -2041,6 +2086,7 @@ VALUE parse_attribute_member(parserstate *state, position comment_pos, VALUE ann
|
|
2041
2086
|
|
2042
2087
|
location = rbs_new_location(state->buffer, member_range);
|
2043
2088
|
loc = rbs_check_location(location);
|
2089
|
+
rbs_loc_alloc_children(loc, 7);
|
2044
2090
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2045
2091
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
2046
2092
|
rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
|
@@ -2138,6 +2184,7 @@ VALUE parse_interface_decl(parserstate *state, position comment_pos, VALUE annot
|
|
2138
2184
|
|
2139
2185
|
VALUE location = rbs_new_location(state->buffer, member_range);
|
2140
2186
|
rbs_loc *loc = rbs_check_location(location);
|
2187
|
+
rbs_loc_alloc_children(loc, 4);
|
2141
2188
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2142
2189
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
2143
2190
|
rbs_loc_add_required_child(loc, rb_intern("end"), end_range);
|
@@ -2183,6 +2230,7 @@ void parse_module_self_types(parserstate *state, VALUE array) {
|
|
2183
2230
|
|
2184
2231
|
VALUE location = rbs_new_location(state->buffer, self_range);
|
2185
2232
|
rbs_loc *loc = rbs_check_location(location);
|
2233
|
+
rbs_loc_alloc_children(loc, 2);
|
2186
2234
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
2187
2235
|
rbs_loc_add_optional_child(loc, rb_intern("args"), args_range);
|
2188
2236
|
|
@@ -2319,6 +2367,7 @@ VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE module_n
|
|
2319
2367
|
|
2320
2368
|
VALUE location = rbs_new_location(state->buffer, decl_range);
|
2321
2369
|
rbs_loc *loc = rbs_check_location(location);
|
2370
|
+
rbs_loc_alloc_children(loc, 6);
|
2322
2371
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2323
2372
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
2324
2373
|
rbs_loc_add_required_child(loc, rb_intern("end"), end_range);
|
@@ -2368,6 +2417,7 @@ VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotati
|
|
2368
2417
|
|
2369
2418
|
VALUE location = rbs_new_location(state->buffer, decl_range);
|
2370
2419
|
rbs_loc *loc = rbs_check_location(location);
|
2420
|
+
rbs_loc_alloc_children(loc, 4);
|
2371
2421
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2372
2422
|
rbs_loc_add_required_child(loc, rb_intern("new_name"), module_name_range);
|
2373
2423
|
rbs_loc_add_required_child(loc, rb_intern("eq"), eq_range);
|
@@ -2404,6 +2454,7 @@ VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
|
|
2404
2454
|
|
2405
2455
|
location = rbs_new_location(state->buffer, super_range);
|
2406
2456
|
loc = rbs_check_location(location);
|
2457
|
+
rbs_loc_alloc_children(loc, 2);
|
2407
2458
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
2408
2459
|
rbs_loc_add_optional_child(loc, rb_intern("args"), args_range);
|
2409
2460
|
|
@@ -2446,6 +2497,7 @@ VALUE parse_class_decl0(parserstate *state, range keyword_range, VALUE name, ran
|
|
2446
2497
|
|
2447
2498
|
location = rbs_new_location(state->buffer, decl_range);
|
2448
2499
|
loc = rbs_check_location(location);
|
2500
|
+
rbs_loc_alloc_children(loc, 5);
|
2449
2501
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2450
2502
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
2451
2503
|
rbs_loc_add_required_child(loc, rb_intern("end"), end_range);
|
@@ -2491,6 +2543,7 @@ VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE annotatio
|
|
2491
2543
|
|
2492
2544
|
VALUE location = rbs_new_location(state->buffer, decl_range);
|
2493
2545
|
rbs_loc *loc = rbs_check_location(location);
|
2546
|
+
rbs_loc_alloc_children(loc, 4);
|
2494
2547
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2495
2548
|
rbs_loc_add_required_child(loc, rb_intern("new_name"), class_name_range);
|
2496
2549
|
rbs_loc_add_required_child(loc, rb_intern("eq"), eq_range);
|
@@ -2664,6 +2717,7 @@ void parse_use_clauses(parserstate *state, VALUE clauses) {
|
|
2664
2717
|
|
2665
2718
|
VALUE location = rbs_new_location(state->buffer, clause_range);
|
2666
2719
|
rbs_loc *loc = rbs_check_location(location);
|
2720
|
+
rbs_loc_alloc_children(loc, 3);
|
2667
2721
|
rbs_loc_add_required_child(loc, rb_intern("type_name"), type_name_range);
|
2668
2722
|
rbs_loc_add_optional_child(loc, rb_intern("keyword"), keyword_range);
|
2669
2723
|
rbs_loc_add_optional_child(loc, rb_intern("new_name"), new_name_range);
|
@@ -2681,6 +2735,7 @@ void parse_use_clauses(parserstate *state, VALUE clauses) {
|
|
2681
2735
|
|
2682
2736
|
VALUE location = rbs_new_location(state->buffer, clause_range);
|
2683
2737
|
rbs_loc *loc = rbs_check_location(location);
|
2738
|
+
rbs_loc_alloc_children(loc, 2);
|
2684
2739
|
rbs_loc_add_required_child(loc, rb_intern("namespace"), namespace_range);
|
2685
2740
|
rbs_loc_add_required_child(loc, rb_intern("star"), star_range);
|
2686
2741
|
|
@@ -2723,6 +2778,7 @@ VALUE parse_use_directive(parserstate *state) {
|
|
2723
2778
|
|
2724
2779
|
VALUE location = rbs_new_location(state->buffer, directive_range);
|
2725
2780
|
rbs_loc *loc = rbs_check_location(location);
|
2781
|
+
rbs_loc_alloc_children(loc, 1);
|
2726
2782
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2727
2783
|
|
2728
2784
|
return rbs_ast_directives_use(clauses, location);
|
@@ -2755,6 +2811,7 @@ rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, V
|
|
2755
2811
|
parserstate *parser = alloc_parser(buffer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
|
2756
2812
|
|
2757
2813
|
if (parser->next_token.type == pEOF) {
|
2814
|
+
free_parser(parser);
|
2758
2815
|
return Qnil;
|
2759
2816
|
}
|
2760
2817
|
|
@@ -2775,6 +2832,7 @@ rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end
|
|
2775
2832
|
parserstate *parser = alloc_parser(buffer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
|
2776
2833
|
|
2777
2834
|
if (parser->next_token.type == pEOF) {
|
2835
|
+
free_parser(parser);
|
2778
2836
|
return Qnil;
|
2779
2837
|
}
|
2780
2838
|
|
@@ -277,6 +277,10 @@ parserstate *alloc_parser(VALUE buffer, int start_pos, int end_pos, VALUE variab
|
|
277
277
|
|
278
278
|
StringValue(string);
|
279
279
|
|
280
|
+
if (start_pos < 0 || end_pos < 0) {
|
281
|
+
rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
|
282
|
+
}
|
283
|
+
|
280
284
|
lexstate *lexer = calloc(1, sizeof(lexstate));
|
281
285
|
lexer->string = string;
|
282
286
|
lexer->current.line = 1;
|
@@ -170,6 +170,17 @@ VALUE rbs_function_param(VALUE type, VALUE name, VALUE location) {
|
|
170
170
|
);
|
171
171
|
}
|
172
172
|
|
173
|
+
VALUE rbs_untyped_function(VALUE return_type) {
|
174
|
+
VALUE args = rb_hash_new();
|
175
|
+
rb_hash_aset(args, ID2SYM(rb_intern("return_type")), return_type);
|
176
|
+
|
177
|
+
return CLASS_NEW_INSTANCE(
|
178
|
+
RBS_Types_UntypedFunction,
|
179
|
+
1,
|
180
|
+
&args
|
181
|
+
);
|
182
|
+
}
|
183
|
+
|
173
184
|
VALUE rbs_function(
|
174
185
|
VALUE required_positional_params,
|
175
186
|
VALUE optional_positional_params,
|
@@ -234,10 +245,10 @@ VALUE rbs_literal(VALUE literal, VALUE location) {
|
|
234
245
|
);
|
235
246
|
}
|
236
247
|
|
237
|
-
VALUE rbs_record(VALUE fields,
|
248
|
+
VALUE rbs_record(VALUE fields,VALUE location) {
|
238
249
|
VALUE args = rb_hash_new();
|
239
250
|
rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
|
240
|
-
rb_hash_aset(args, ID2SYM(rb_intern("
|
251
|
+
rb_hash_aset(args, ID2SYM(rb_intern("all_fields")), fields);
|
241
252
|
|
242
253
|
return CLASS_NEW_INSTANCE(
|
243
254
|
RBS_Types_Record,
|
@@ -588,4 +599,3 @@ VALUE rbs_ast_directives_use_wildcard_clause(VALUE namespace, VALUE location) {
|
|
588
599
|
|
589
600
|
return CLASS_NEW_INSTANCE(RBS_AST_Directives_Use_WildcardClause, 1, &kwargs);
|
590
601
|
}
|
591
|
-
|
@@ -30,6 +30,7 @@ VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location);
|
|
30
30
|
VALUE rbs_class_singleton(VALUE typename, VALUE location);
|
31
31
|
VALUE rbs_function_param(VALUE type, VALUE name, VALUE location);
|
32
32
|
VALUE rbs_function(VALUE required_positional_params, VALUE optional_positional_params, VALUE rest_positional_params, VALUE trailing_positional_params, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type);
|
33
|
+
VALUE rbs_untyped_function(VALUE return_type);
|
33
34
|
VALUE rbs_interface(VALUE typename, VALUE type_args, VALUE location);
|
34
35
|
VALUE rbs_intersection(VALUE types, VALUE location);
|
35
36
|
VALUE rbs_literal(VALUE literal, VALUE location);
|
@@ -152,12 +152,7 @@ module RBS
|
|
152
152
|
private def need_to_fetch?(revision)
|
153
153
|
return true unless commit_hash?
|
154
154
|
|
155
|
-
|
156
|
-
git('cat-file', '-e', revision)
|
157
|
-
false
|
158
|
-
rescue CommandError
|
159
|
-
true
|
160
|
-
end
|
155
|
+
!git?('cat-file', '-e', revision)
|
161
156
|
end
|
162
157
|
|
163
158
|
private def git_dir
|
@@ -4,7 +4,7 @@ module RBS
|
|
4
4
|
class DefinitionBuilder
|
5
5
|
class MethodBuilder
|
6
6
|
class Methods
|
7
|
-
Definition
|
7
|
+
class Definition < Struct.new(:name, :type, :originals, :overloads, :accessibilities, keyword_init: true)
|
8
8
|
# @implements Definition
|
9
9
|
|
10
10
|
def original
|
@@ -630,12 +630,12 @@ module RBS
|
|
630
630
|
end
|
631
631
|
|
632
632
|
# @type var accessibility: RBS::Definition::accessibility
|
633
|
-
accessibility =
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
633
|
+
accessibility =
|
634
|
+
if original.instance? && [:initialize, :initialize_copy, :initialize_clone, :initialize_dup, :respond_to_missing?].include?(method.name)
|
635
|
+
:private
|
636
|
+
else
|
637
|
+
method.accessibility
|
638
|
+
end
|
639
639
|
# Skip setting up `super_method` if `implemented_in` is `nil`, that means the type doesn't have implementation.
|
640
640
|
# This typically happens if the type is an interface.
|
641
641
|
if implemented_in
|
@@ -669,7 +669,7 @@ module RBS
|
|
669
669
|
]
|
670
670
|
),
|
671
671
|
block: nil,
|
672
|
-
location:
|
672
|
+
location: original.location
|
673
673
|
)
|
674
674
|
else
|
675
675
|
# getter
|
@@ -677,7 +677,7 @@ module RBS
|
|
677
677
|
type_params: [],
|
678
678
|
type: Types::Function.empty(attr_type),
|
679
679
|
block: nil,
|
680
|
-
location:
|
680
|
+
location: original.location
|
681
681
|
)
|
682
682
|
end
|
683
683
|
|
data/lib/rbs/diff.rb
CHANGED
@@ -83,7 +83,7 @@ module RBS
|
|
83
83
|
manifest_pathname = dir_pathname / 'manifest.yaml'
|
84
84
|
if manifest_pathname.exist?
|
85
85
|
manifest = YAML.safe_load(manifest_pathname.read)
|
86
|
-
if manifest['dependencies']
|
86
|
+
if manifest && manifest['dependencies']
|
87
87
|
manifest['dependencies'].each do |dependency|
|
88
88
|
loader.add(library: dependency['name'], version: nil)
|
89
89
|
end
|
data/lib/rbs/errors.rb
CHANGED
@@ -62,20 +62,6 @@ module RBS
|
|
62
62
|
|
63
63
|
super "#{Location.to_string location}: Syntax error: #{error_message}, token=`#{location.source}` (#{token_type})"
|
64
64
|
end
|
65
|
-
|
66
|
-
def error_value
|
67
|
-
RBS.print_warning {
|
68
|
-
"#{self.class.name}#error_value is deprecated and will be deleted in RBS 2.0. Consider using `location.source` instead."
|
69
|
-
}
|
70
|
-
location.source
|
71
|
-
end
|
72
|
-
|
73
|
-
def token_str
|
74
|
-
RBS.print_warning {
|
75
|
-
"#{self.class.name}#token_str is deprecated and will be deleted in RBS 2.0. Consider using `token_type` instead."
|
76
|
-
}
|
77
|
-
token_type
|
78
|
-
end
|
79
65
|
end
|
80
66
|
|
81
67
|
class InvalidTypeApplicationError < DefinitionError
|
data/lib/rbs/parser_aux.rb
CHANGED
@@ -28,11 +28,6 @@ module RBS
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
autoload :SyntaxError, "rbs/parser_compat/syntax_error"
|
32
|
-
autoload :SemanticsError, "rbs/parser_compat/semantics_error"
|
33
|
-
autoload :LexerError, "rbs/parser_compat/lexer_error"
|
34
|
-
autoload :LocatedValue, "rbs/parser_compat/located_value"
|
35
|
-
|
36
31
|
KEYWORDS = %w(
|
37
32
|
bool
|
38
33
|
bot
|
@@ -37,13 +37,9 @@ module RBS
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
method_block = Types::Block.new(
|
41
|
-
required: required,
|
42
|
-
type: Types::Function.empty(untyped),
|
43
|
-
self_type: nil
|
44
|
-
)
|
45
|
-
|
46
40
|
if yields
|
41
|
+
function = Types::Function.empty(untyped)
|
42
|
+
|
47
43
|
yields.each do |yield_node|
|
48
44
|
array_content = yield_node.children[0]&.children&.compact || []
|
49
45
|
|
@@ -54,9 +50,9 @@ module RBS
|
|
54
50
|
[array_content, nil]
|
55
51
|
end
|
56
52
|
|
57
|
-
if (diff = positionals.size -
|
53
|
+
if (diff = positionals.size - function.required_positionals.size) > 0
|
58
54
|
diff.times do
|
59
|
-
|
55
|
+
function.required_positionals << Types::Function::Param.new(
|
60
56
|
type: untyped,
|
61
57
|
name: nil
|
62
58
|
)
|
@@ -67,7 +63,7 @@ module RBS
|
|
67
63
|
keywords.children[0].children.each_slice(2) do |key_node, value_node|
|
68
64
|
if key_node
|
69
65
|
key = key_node.children[0]
|
70
|
-
|
66
|
+
function.required_keywords[key] ||=
|
71
67
|
Types::Function::Param.new(
|
72
68
|
type: untyped,
|
73
69
|
name: nil
|
@@ -76,10 +72,13 @@ module RBS
|
|
76
72
|
end
|
77
73
|
end
|
78
74
|
end
|
75
|
+
else
|
76
|
+
function = Types::UntypedFunction.new(return_type: untyped)
|
79
77
|
end
|
80
|
-
end
|
81
78
|
|
82
|
-
|
79
|
+
|
80
|
+
Types::Block.new(required: required, type: function, self_type: nil)
|
81
|
+
end
|
83
82
|
end
|
84
83
|
|
85
84
|
def each_child(node, &block)
|
@@ -109,7 +108,7 @@ module RBS
|
|
109
108
|
def keyword_hash?(node)
|
110
109
|
if node && node.type == :HASH
|
111
110
|
node.children[0].children.compact.each_slice(2).all? {|key, _|
|
112
|
-
|
111
|
+
symbol_literal_node?(key)
|
113
112
|
}
|
114
113
|
else
|
115
114
|
false
|
@@ -122,6 +121,17 @@ module RBS
|
|
122
121
|
args_node&.children || [0, nil, nil, nil, 0, nil, nil, nil, nil, nil]
|
123
122
|
end
|
124
123
|
|
124
|
+
def symbol_literal_node?(node)
|
125
|
+
case node.type
|
126
|
+
when :LIT
|
127
|
+
if node.children[0].is_a?(Symbol)
|
128
|
+
node.children[0]
|
129
|
+
end
|
130
|
+
when :SYM
|
131
|
+
node.children[0]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
125
135
|
def untyped
|
126
136
|
@untyped ||= Types::Bases::Any.new(location: nil)
|
127
137
|
end
|