rbs-relaxed 3.9.0.1 → 3.9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +24 -2
- data/.github/workflows/typecheck.yml +0 -2
- data/.github/workflows/windows.yml +1 -1
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +93 -0
- data/Rakefile +17 -2
- data/config.yml +4 -0
- data/core/data.rbs +1 -1
- data/core/enumerator.rbs +14 -2
- data/core/exception.rbs +1 -1
- data/core/hash.rbs +2 -2
- data/core/kernel.rbs +4 -4
- data/core/method.rbs +2 -2
- data/core/module.rbs +4 -4
- data/core/object.rbs +1 -1
- data/core/proc.rbs +2 -2
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/rubygems/version.rbs +2 -2
- data/core/string.rbs +3 -3
- data/core/unbound_method.rbs +1 -1
- data/ext/rbs_extension/parser.c +59 -50
- data/ext/rbs_extension/parserstate.c +15 -1
- data/include/rbs/ruby_objs.h +4 -4
- data/lib/rbs/ast/declarations.rb +9 -4
- data/lib/rbs/ast/type_param.rb +0 -10
- data/lib/rbs/collection/config/lockfile_generator.rb +29 -3
- data/lib/rbs/definition.rb +40 -31
- data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
- data/lib/rbs/definition_builder.rb +86 -34
- data/lib/rbs/environment.rb +8 -4
- data/lib/rbs/errors.rb +10 -31
- data/lib/rbs/prototype/rb.rb +2 -1
- data/lib/rbs/prototype/rbi.rb +2 -1
- data/lib/rbs/prototype/runtime.rb +3 -0
- data/lib/rbs/types.rb +3 -7
- data/lib/rbs/unit_test/type_assertions.rb +2 -2
- data/lib/rbs/unit_test/with_aliases.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/sig/annotate/rdoc_source.rbs +2 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/config/lockfile_generator.rbs +1 -1
- data/sig/declarations.rbs +10 -3
- data/sig/definition.rbs +67 -14
- data/sig/definition_builder.rbs +17 -3
- data/sig/errors.rbs +7 -10
- data/sig/namespace.rbs +1 -1
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +0 -3
- data/src/ruby_objs.c +8 -4
- data/src/util/rbs_constant_pool.c +1 -1
- data/stdlib/cgi/0/core.rbs +10 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -0
- data/stdlib/net-http/0/net-http.rbs +1 -1
- data/stdlib/openssl/0/openssl.rbs +67 -67
- data/stdlib/resolv/0/resolv.rbs +8 -8
- data/stdlib/socket/0/addrinfo.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1 -1
- data/stdlib/uri/0/common.rbs +17 -0
- metadata +3 -6
data/ext/rbs_extension/parser.c
CHANGED
|
@@ -61,6 +61,7 @@ typedef struct {
|
|
|
61
61
|
} method_params;
|
|
62
62
|
|
|
63
63
|
static VALUE EMPTY_ARRAY;
|
|
64
|
+
static VALUE EMPTY_HASH;
|
|
64
65
|
|
|
65
66
|
static inline void melt_array(VALUE *array) {
|
|
66
67
|
if (*array == EMPTY_ARRAY) {
|
|
@@ -68,6 +69,12 @@ static inline void melt_array(VALUE *array) {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
static inline void melt_hash(VALUE *hash) {
|
|
73
|
+
if (*hash == EMPTY_HASH) {
|
|
74
|
+
*hash = rb_hash_new();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
static bool rbs_is_untyped_params(method_params *params) {
|
|
72
79
|
return NIL_P(params->required_positionals);
|
|
73
80
|
}
|
|
@@ -343,7 +350,7 @@ static VALUE parse_keyword_key(parserstate *state) {
|
|
|
343
350
|
/*
|
|
344
351
|
keyword ::= {} keyword `:` <function_param>
|
|
345
352
|
*/
|
|
346
|
-
static void parse_keyword(parserstate *state, VALUE keywords, VALUE memo) {
|
|
353
|
+
static void parse_keyword(parserstate *state, VALUE *keywords, VALUE memo) {
|
|
347
354
|
VALUE key = parse_keyword_key(state);
|
|
348
355
|
|
|
349
356
|
if (!NIL_P(rb_hash_aref(memo, key))) {
|
|
@@ -359,7 +366,8 @@ static void parse_keyword(parserstate *state, VALUE keywords, VALUE memo) {
|
|
|
359
366
|
parser_advance_assert(state, pCOLON);
|
|
360
367
|
VALUE param = parse_function_param(state);
|
|
361
368
|
|
|
362
|
-
|
|
369
|
+
melt_hash(keywords);
|
|
370
|
+
rb_hash_aset(*keywords, key, param);
|
|
363
371
|
|
|
364
372
|
return;
|
|
365
373
|
}
|
|
@@ -466,7 +474,7 @@ PARSE_OPTIONAL_PARAMS:
|
|
|
466
474
|
parser_advance(state);
|
|
467
475
|
|
|
468
476
|
if (is_keyword(state)) {
|
|
469
|
-
parse_keyword(state, params->optional_keywords, memo);
|
|
477
|
+
parse_keyword(state, ¶ms->optional_keywords, memo);
|
|
470
478
|
parser_advance_if(state, pCOMMA);
|
|
471
479
|
goto PARSE_KEYWORDS;
|
|
472
480
|
}
|
|
@@ -533,7 +541,7 @@ PARSE_KEYWORDS:
|
|
|
533
541
|
case pQUESTION:
|
|
534
542
|
parser_advance(state);
|
|
535
543
|
if (is_keyword(state)) {
|
|
536
|
-
parse_keyword(state, params->optional_keywords, memo);
|
|
544
|
+
parse_keyword(state, ¶ms->optional_keywords, memo);
|
|
537
545
|
} else {
|
|
538
546
|
raise_syntax_error(
|
|
539
547
|
state,
|
|
@@ -556,7 +564,7 @@ PARSE_KEYWORDS:
|
|
|
556
564
|
case tBANGIDENT:
|
|
557
565
|
KEYWORD_CASES
|
|
558
566
|
if (is_keyword(state)) {
|
|
559
|
-
parse_keyword(state, params->required_keywords, memo);
|
|
567
|
+
parse_keyword(state, ¶ms->required_keywords, memo);
|
|
560
568
|
} else {
|
|
561
569
|
raise_syntax_error(
|
|
562
570
|
state,
|
|
@@ -613,8 +621,8 @@ static void initialize_method_params(method_params *params){
|
|
|
613
621
|
.optional_positionals = EMPTY_ARRAY,
|
|
614
622
|
.rest_positionals = Qnil,
|
|
615
623
|
.trailing_positionals = EMPTY_ARRAY,
|
|
616
|
-
.required_keywords =
|
|
617
|
-
.optional_keywords =
|
|
624
|
+
.required_keywords = EMPTY_HASH,
|
|
625
|
+
.optional_keywords = EMPTY_HASH,
|
|
618
626
|
.rest_keywords = Qnil,
|
|
619
627
|
};
|
|
620
628
|
}
|
|
@@ -653,16 +661,16 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block, VA
|
|
|
653
661
|
parser_advance_assert(state, pRPAREN);
|
|
654
662
|
}
|
|
655
663
|
|
|
656
|
-
// Untyped method parameter means it cannot have block
|
|
657
|
-
if (rbs_is_untyped_params(¶ms)) {
|
|
658
|
-
if (state->next_token.type != pARROW) {
|
|
659
|
-
raise_syntax_error(state, state->next_token2, "A method type with untyped method parameter cannot have block");
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
664
|
// Passing NULL to function_self_type means the function itself doesn't accept self type binding. (== method type)
|
|
664
665
|
if (function_self_type) {
|
|
665
666
|
*function_self_type = parse_self_type_binding(state);
|
|
667
|
+
} else {
|
|
668
|
+
// Parsing method type. untyped_params means it cannot have a block
|
|
669
|
+
if (rbs_is_untyped_params(¶ms)) {
|
|
670
|
+
if (state->next_token.type != pARROW) {
|
|
671
|
+
raise_syntax_error(state, state->next_token2, "A method type with untyped method parameter cannot have block");
|
|
672
|
+
}
|
|
673
|
+
}
|
|
666
674
|
}
|
|
667
675
|
|
|
668
676
|
VALUE required = Qtrue;
|
|
@@ -1088,26 +1096,24 @@ static VALUE parse_simple(parserstate *state) {
|
|
|
1088
1096
|
| {} <optional>
|
|
1089
1097
|
*/
|
|
1090
1098
|
static VALUE parse_intersection(parserstate *state) {
|
|
1091
|
-
range
|
|
1092
|
-
rg.start = state->next_token.range.start;
|
|
1093
|
-
|
|
1099
|
+
position start = state->next_token.range.start;
|
|
1094
1100
|
VALUE type = parse_optional(state);
|
|
1095
|
-
|
|
1101
|
+
if (state->next_token.type != pAMP) {
|
|
1102
|
+
return type;
|
|
1103
|
+
}
|
|
1096
1104
|
|
|
1105
|
+
VALUE intersection_types = rb_ary_new();
|
|
1097
1106
|
rb_ary_push(intersection_types, type);
|
|
1098
1107
|
while (state->next_token.type == pAMP) {
|
|
1099
1108
|
parser_advance(state);
|
|
1100
1109
|
rb_ary_push(intersection_types, parse_optional(state));
|
|
1101
1110
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
return type;
|
|
1111
|
+
range rg = (range) {
|
|
1112
|
+
.start = start,
|
|
1113
|
+
.end = state->current_token.range.end,
|
|
1114
|
+
};
|
|
1115
|
+
VALUE location = rbs_new_location(state->buffer, rg);
|
|
1116
|
+
return rbs_intersection(intersection_types, location);
|
|
1111
1117
|
}
|
|
1112
1118
|
|
|
1113
1119
|
/*
|
|
@@ -1115,26 +1121,24 @@ static VALUE parse_intersection(parserstate *state) {
|
|
|
1115
1121
|
| {} <intersection>
|
|
1116
1122
|
*/
|
|
1117
1123
|
VALUE parse_type(parserstate *state) {
|
|
1118
|
-
range
|
|
1119
|
-
rg.start = state->next_token.range.start;
|
|
1120
|
-
|
|
1124
|
+
position start = state->next_token.range.start;
|
|
1121
1125
|
VALUE type = parse_intersection(state);
|
|
1122
|
-
|
|
1126
|
+
if (state->next_token.type != pBAR) {
|
|
1127
|
+
return type;
|
|
1128
|
+
}
|
|
1123
1129
|
|
|
1130
|
+
VALUE union_types = rb_ary_new();
|
|
1124
1131
|
rb_ary_push(union_types, type);
|
|
1125
1132
|
while (state->next_token.type == pBAR) {
|
|
1126
1133
|
parser_advance(state);
|
|
1127
1134
|
rb_ary_push(union_types, parse_intersection(state));
|
|
1128
1135
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
return type;
|
|
1136
|
+
range rg = (range) {
|
|
1137
|
+
.start = start,
|
|
1138
|
+
.end = state->current_token.range.end,
|
|
1139
|
+
};
|
|
1140
|
+
VALUE location = rbs_new_location(state->buffer, rg);
|
|
1141
|
+
return rbs_union(union_types, location);
|
|
1138
1142
|
}
|
|
1139
1143
|
|
|
1140
1144
|
/*
|
|
@@ -1314,7 +1318,7 @@ VALUE parse_method_type(parserstate *state) {
|
|
|
1314
1318
|
/*
|
|
1315
1319
|
global_decl ::= {tGIDENT} `:` <type>
|
|
1316
1320
|
*/
|
|
1317
|
-
static VALUE parse_global_decl(parserstate *state) {
|
|
1321
|
+
static VALUE parse_global_decl(parserstate *state, VALUE annotations) {
|
|
1318
1322
|
range decl_range;
|
|
1319
1323
|
decl_range.start = state->current_token.range.start;
|
|
1320
1324
|
|
|
@@ -1334,13 +1338,13 @@ static VALUE parse_global_decl(parserstate *state) {
|
|
|
1334
1338
|
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1335
1339
|
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1336
1340
|
|
|
1337
|
-
return rbs_ast_decl_global(typename, type, location, comment);
|
|
1341
|
+
return rbs_ast_decl_global(typename, type, location, comment, annotations);
|
|
1338
1342
|
}
|
|
1339
1343
|
|
|
1340
1344
|
/*
|
|
1341
1345
|
const_decl ::= {const_name} `:` <type>
|
|
1342
1346
|
*/
|
|
1343
|
-
static VALUE parse_const_decl(parserstate *state) {
|
|
1347
|
+
static VALUE parse_const_decl(parserstate *state, VALUE annotations) {
|
|
1344
1348
|
range decl_range;
|
|
1345
1349
|
|
|
1346
1350
|
decl_range.start = state->current_token.range.start;
|
|
@@ -1361,7 +1365,7 @@ static VALUE parse_const_decl(parserstate *state) {
|
|
|
1361
1365
|
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1362
1366
|
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1363
1367
|
|
|
1364
|
-
return rbs_ast_decl_constant(typename, type, location, comment);
|
|
1368
|
+
return rbs_ast_decl_constant(typename, type, location, comment, annotations);
|
|
1365
1369
|
}
|
|
1366
1370
|
|
|
1367
1371
|
/*
|
|
@@ -2465,7 +2469,7 @@ static VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE a
|
|
|
2465
2469
|
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2466
2470
|
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2467
2471
|
|
|
2468
|
-
return rbs_ast_decl_module_alias(module_name, old_name, location, comment);
|
|
2472
|
+
return rbs_ast_decl_module_alias(module_name, old_name, location, comment, annotations);
|
|
2469
2473
|
} else {
|
|
2470
2474
|
return parse_module_decl0(state, keyword_range, module_name, module_name_range, comment, annotations);
|
|
2471
2475
|
}
|
|
@@ -2582,7 +2586,7 @@ static VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE an
|
|
|
2582
2586
|
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2583
2587
|
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2584
2588
|
|
|
2585
|
-
return rbs_ast_decl_class_alias(class_name, old_name, location, comment);
|
|
2589
|
+
return rbs_ast_decl_class_alias(class_name, old_name, location, comment, annotations);
|
|
2586
2590
|
} else {
|
|
2587
2591
|
return parse_class_decl0(state, keyword_range, class_name, class_name_range, comment, annotations);
|
|
2588
2592
|
}
|
|
@@ -2602,11 +2606,11 @@ static VALUE parse_nested_decl(parserstate *state, const char *nested_in, positi
|
|
|
2602
2606
|
switch (state->current_token.type) {
|
|
2603
2607
|
case tUIDENT:
|
|
2604
2608
|
case pCOLON2: {
|
|
2605
|
-
decl = parse_const_decl(state);
|
|
2609
|
+
decl = parse_const_decl(state, annotations);
|
|
2606
2610
|
break;
|
|
2607
2611
|
}
|
|
2608
2612
|
case tGIDENT: {
|
|
2609
|
-
decl = parse_global_decl(state);
|
|
2613
|
+
decl = parse_global_decl(state, annotations);
|
|
2610
2614
|
break;
|
|
2611
2615
|
}
|
|
2612
2616
|
case kTYPE: {
|
|
@@ -2648,10 +2652,10 @@ static VALUE parse_decl(parserstate *state) {
|
|
|
2648
2652
|
switch (state->current_token.type) {
|
|
2649
2653
|
case tUIDENT:
|
|
2650
2654
|
case pCOLON2: {
|
|
2651
|
-
return parse_const_decl(state);
|
|
2655
|
+
return parse_const_decl(state, annotations);
|
|
2652
2656
|
}
|
|
2653
2657
|
case tGIDENT: {
|
|
2654
|
-
return parse_global_decl(state);
|
|
2658
|
+
return parse_global_decl(state, annotations);
|
|
2655
2659
|
}
|
|
2656
2660
|
case kTYPE: {
|
|
2657
2661
|
return parse_type_decl(state, annot_pos, annotations);
|
|
@@ -2962,10 +2966,15 @@ rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) {
|
|
|
2962
2966
|
void rbs__init_parser(void) {
|
|
2963
2967
|
RBS_Parser = rb_define_class_under(RBS, "Parser", rb_cObject);
|
|
2964
2968
|
rb_gc_register_mark_object(RBS_Parser);
|
|
2969
|
+
|
|
2965
2970
|
VALUE empty_array = rb_obj_freeze(rb_ary_new());
|
|
2966
2971
|
rb_gc_register_mark_object(empty_array);
|
|
2967
2972
|
EMPTY_ARRAY = empty_array;
|
|
2968
2973
|
|
|
2974
|
+
VALUE empty_hash = rb_obj_freeze(rb_hash_new());
|
|
2975
|
+
rb_gc_register_mark_object(empty_hash);
|
|
2976
|
+
EMPTY_HASH = empty_hash;
|
|
2977
|
+
|
|
2969
2978
|
rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 5);
|
|
2970
2979
|
rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5);
|
|
2971
2980
|
rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 3);
|
|
@@ -334,7 +334,7 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
|
|
|
334
334
|
.vars = NULL,
|
|
335
335
|
.last_comment = NULL,
|
|
336
336
|
|
|
337
|
-
.constant_pool = {},
|
|
337
|
+
.constant_pool = { 0 },
|
|
338
338
|
};
|
|
339
339
|
|
|
340
340
|
// The parser's constant pool is mainly used for storing the names of type variables, which usually aren't many.
|
|
@@ -363,6 +363,7 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
|
|
|
363
363
|
|
|
364
364
|
if (!NIL_P(variables)) {
|
|
365
365
|
if (!RB_TYPE_P(variables, T_ARRAY)) {
|
|
366
|
+
free_parser(parser);
|
|
366
367
|
rb_raise(rb_eTypeError,
|
|
367
368
|
"wrong argument type %"PRIsVALUE" (must be array or nil)",
|
|
368
369
|
rb_obj_class(variables));
|
|
@@ -387,11 +388,24 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
|
|
|
387
388
|
return parser;
|
|
388
389
|
}
|
|
389
390
|
|
|
391
|
+
void free_typevar_tables(id_table *table) {
|
|
392
|
+
while (table != NULL) {
|
|
393
|
+
id_table *next = table->next;
|
|
394
|
+
if (table->ids != NULL) {
|
|
395
|
+
free(table->ids);
|
|
396
|
+
}
|
|
397
|
+
free(table);
|
|
398
|
+
table = next;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
390
402
|
void free_parser(parserstate *parser) {
|
|
391
403
|
free(parser->lexstate);
|
|
392
404
|
if (parser->last_comment) {
|
|
393
405
|
free_comment(parser->last_comment);
|
|
394
406
|
}
|
|
407
|
+
|
|
408
|
+
free_typevar_tables(parser->vars);
|
|
395
409
|
rbs_constant_pool_free(&parser->constant_pool);
|
|
396
410
|
free(parser);
|
|
397
411
|
}
|
data/include/rbs/ruby_objs.h
CHANGED
|
@@ -14,13 +14,13 @@ VALUE rbs_ast_annotation(VALUE string, VALUE location);
|
|
|
14
14
|
VALUE rbs_ast_comment(VALUE string, VALUE location);
|
|
15
15
|
VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
|
16
16
|
VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
|
|
17
|
-
VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
|
|
18
|
-
VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment);
|
|
19
|
-
VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment);
|
|
17
|
+
VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment, VALUE annotations);
|
|
18
|
+
VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment, VALUE annotations);
|
|
19
|
+
VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment, VALUE annotations);
|
|
20
20
|
VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
|
21
21
|
VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
|
22
22
|
VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
|
|
23
|
-
VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
|
|
23
|
+
VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment, VALUE annotations);
|
|
24
24
|
VALUE rbs_ast_decl_type_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
|
|
25
25
|
VALUE rbs_ast_directives_use(VALUE clauses, VALUE location);
|
|
26
26
|
VALUE rbs_ast_directives_use_single_clause(VALUE type_name, VALUE new_name, VALUE location);
|
data/lib/rbs/ast/declarations.rb
CHANGED
|
@@ -349,12 +349,14 @@ module RBS
|
|
|
349
349
|
attr_reader :type
|
|
350
350
|
attr_reader :location
|
|
351
351
|
attr_reader :comment
|
|
352
|
+
attr_reader :annotations
|
|
352
353
|
|
|
353
|
-
def initialize(name:, type:, location:, comment:)
|
|
354
|
+
def initialize(name:, type:, location:, comment:, annotations: [])
|
|
354
355
|
@name = name
|
|
355
356
|
@type = type
|
|
356
357
|
@location = location
|
|
357
358
|
@comment = comment
|
|
359
|
+
@annotations = annotations || []
|
|
358
360
|
end
|
|
359
361
|
|
|
360
362
|
def ==(other)
|
|
@@ -385,12 +387,14 @@ module RBS
|
|
|
385
387
|
attr_reader :type
|
|
386
388
|
attr_reader :location
|
|
387
389
|
attr_reader :comment
|
|
390
|
+
attr_reader :annotations
|
|
388
391
|
|
|
389
|
-
def initialize(name:, type:, location:, comment:)
|
|
392
|
+
def initialize(name:, type:, location:, comment:, annotations: [])
|
|
390
393
|
@name = name
|
|
391
394
|
@type = type
|
|
392
395
|
@location = location
|
|
393
396
|
@comment = comment
|
|
397
|
+
@annotations = annotations
|
|
394
398
|
end
|
|
395
399
|
|
|
396
400
|
def ==(other)
|
|
@@ -417,13 +421,14 @@ module RBS
|
|
|
417
421
|
end
|
|
418
422
|
|
|
419
423
|
class AliasDecl < Base
|
|
420
|
-
attr_reader :new_name, :old_name, :location, :comment
|
|
424
|
+
attr_reader :new_name, :old_name, :location, :comment, :annotations
|
|
421
425
|
|
|
422
|
-
def initialize(new_name:, old_name:, location:, comment:)
|
|
426
|
+
def initialize(new_name:, old_name:, location:, comment:, annotations: [])
|
|
423
427
|
@new_name = new_name
|
|
424
428
|
@old_name = old_name
|
|
425
429
|
@location = location
|
|
426
430
|
@comment = comment
|
|
431
|
+
@annotations = annotations
|
|
427
432
|
end
|
|
428
433
|
|
|
429
434
|
def ==(other)
|
data/lib/rbs/ast/type_param.rb
CHANGED
|
@@ -56,16 +56,6 @@ module RBS
|
|
|
56
56
|
}.to_json(state)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
def rename(name)
|
|
60
|
-
TypeParam.new(
|
|
61
|
-
name: name,
|
|
62
|
-
variance: variance,
|
|
63
|
-
upper_bound: upper_bound_type,
|
|
64
|
-
location: location,
|
|
65
|
-
default_type: default_type
|
|
66
|
-
).unchecked!(unchecked?)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
59
|
def map_type(&block)
|
|
70
60
|
if b = upper_bound_type
|
|
71
61
|
_upper_bound_type = yield(b)
|
|
@@ -4,7 +4,17 @@ module RBS
|
|
|
4
4
|
module Collection
|
|
5
5
|
class Config
|
|
6
6
|
class LockfileGenerator
|
|
7
|
-
ALUMNI_STDLIBS = {
|
|
7
|
+
ALUMNI_STDLIBS = {
|
|
8
|
+
"mutex_m" => ">= 0.3.0",
|
|
9
|
+
"abbrev" => nil,
|
|
10
|
+
"base64" => nil,
|
|
11
|
+
"bigdecimal" => nil,
|
|
12
|
+
"csv" => nil,
|
|
13
|
+
"minitest" => nil,
|
|
14
|
+
"net-smtp" => nil,
|
|
15
|
+
"nkf" => nil,
|
|
16
|
+
"observer" => nil,
|
|
17
|
+
}
|
|
8
18
|
|
|
9
19
|
class GemfileLockMismatchError < StandardError
|
|
10
20
|
def initialize(expected:, actual:)
|
|
@@ -161,12 +171,24 @@ module RBS
|
|
|
161
171
|
return if lockfile.gems.key?(name)
|
|
162
172
|
|
|
163
173
|
case name
|
|
174
|
+
when 'bigdecimal-math'
|
|
175
|
+
# The `bigdecimal-math` is never released as a gem.
|
|
176
|
+
# Therefore, `assign_gem` should not be called.
|
|
177
|
+
RBS.logger.info {
|
|
178
|
+
from = from_gem || "rbs_collection.yaml"
|
|
179
|
+
"`#{name}` is included in the RBS dependencies of `#{from}`, but the type definition as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies of `#{from}`."
|
|
180
|
+
}
|
|
181
|
+
source = find_source(name: name)
|
|
182
|
+
if source&.is_a?(Sources::Stdlib)
|
|
183
|
+
lockfile.gems[name] = { name: name, version: "0", source: source }
|
|
184
|
+
end
|
|
185
|
+
return
|
|
164
186
|
when *ALUMNI_STDLIBS.keys
|
|
165
187
|
version = ALUMNI_STDLIBS.fetch(name)
|
|
166
188
|
if from_gem
|
|
167
189
|
# From `dependencies:` of a `manifest.yaml` of a gem
|
|
168
190
|
source = find_source(name: name) or raise
|
|
169
|
-
if source.is_a?(Sources::Stdlib)
|
|
191
|
+
if source.is_a?(Sources::Stdlib) && version
|
|
170
192
|
RBS.logger.warn {
|
|
171
193
|
"`#{name}` is included in the RBS dependencies of `#{from_gem}`, but the type definition as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
|
|
172
194
|
}
|
|
@@ -180,7 +202,11 @@ module RBS
|
|
|
180
202
|
else
|
|
181
203
|
# From `gems:` of a `rbs_collection.yaml`
|
|
182
204
|
RBS.logger.warn {
|
|
183
|
-
|
|
205
|
+
if version
|
|
206
|
+
"`#{name}` as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
|
|
207
|
+
else
|
|
208
|
+
"`#{name}` as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies in your rbs_collection.yaml."
|
|
209
|
+
end
|
|
184
210
|
}
|
|
185
211
|
end
|
|
186
212
|
end
|
data/lib/rbs/definition.rb
CHANGED
|
@@ -6,11 +6,13 @@ module RBS
|
|
|
6
6
|
attr_reader :parent_variable
|
|
7
7
|
attr_reader :type
|
|
8
8
|
attr_reader :declared_in
|
|
9
|
+
attr_reader :source
|
|
9
10
|
|
|
10
|
-
def initialize(parent_variable:, type:, declared_in:)
|
|
11
|
+
def initialize(parent_variable:, type:, declared_in:, source:)
|
|
11
12
|
@parent_variable = parent_variable
|
|
12
13
|
@type = type
|
|
13
14
|
@declared_in = declared_in
|
|
15
|
+
@source = source
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def sub(s)
|
|
@@ -19,7 +21,8 @@ module RBS
|
|
|
19
21
|
self.class.new(
|
|
20
22
|
parent_variable: parent_variable,
|
|
21
23
|
type: type.sub(s),
|
|
22
|
-
declared_in: declared_in
|
|
24
|
+
declared_in: declared_in,
|
|
25
|
+
source: source
|
|
23
26
|
)
|
|
24
27
|
end
|
|
25
28
|
end
|
|
@@ -39,9 +42,9 @@ module RBS
|
|
|
39
42
|
@member = member
|
|
40
43
|
@defined_in = defined_in
|
|
41
44
|
@implemented_in = implemented_in
|
|
42
|
-
@member_annotations =
|
|
43
|
-
@overload_annotations =
|
|
44
|
-
@annotations =
|
|
45
|
+
@member_annotations = []
|
|
46
|
+
@overload_annotations = []
|
|
47
|
+
@annotations = []
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
def ==(other)
|
|
@@ -63,7 +66,10 @@ module RBS
|
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
def update(type: self.type, member: self.member, defined_in: self.defined_in, implemented_in: self.implemented_in)
|
|
66
|
-
TypeDef.new(type: type, member: member, defined_in: defined_in, implemented_in: implemented_in
|
|
69
|
+
TypeDef.new(type: type, member: member, defined_in: defined_in, implemented_in: implemented_in).tap do |type_def|
|
|
70
|
+
type_def.overload_annotations.replace(self.overload_annotations)
|
|
71
|
+
type_def.member_annotations.replace(self.member_annotations)
|
|
72
|
+
end
|
|
67
73
|
end
|
|
68
74
|
|
|
69
75
|
def overload?
|
|
@@ -74,20 +80,33 @@ module RBS
|
|
|
74
80
|
false
|
|
75
81
|
end
|
|
76
82
|
end
|
|
83
|
+
|
|
84
|
+
def each_annotation(&block)
|
|
85
|
+
if block
|
|
86
|
+
member_annotations.each(&block)
|
|
87
|
+
overload_annotations.each(&block)
|
|
88
|
+
else
|
|
89
|
+
enum_for :each_annotation
|
|
90
|
+
end
|
|
91
|
+
end
|
|
77
92
|
end
|
|
78
93
|
|
|
79
94
|
attr_reader :super_method
|
|
80
95
|
attr_reader :defs
|
|
81
96
|
attr_reader :accessibility
|
|
82
97
|
attr_reader :extra_annotations
|
|
98
|
+
attr_reader :annotations
|
|
83
99
|
attr_reader :alias_of
|
|
100
|
+
attr_reader :alias_member
|
|
84
101
|
|
|
85
|
-
def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:)
|
|
102
|
+
def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil)
|
|
86
103
|
@super_method = super_method
|
|
87
104
|
@defs = defs
|
|
88
105
|
@accessibility = accessibility
|
|
89
106
|
@extra_annotations = []
|
|
107
|
+
@annotations = []
|
|
90
108
|
@alias_of = alias_of
|
|
109
|
+
@alias_member = alias_member
|
|
91
110
|
end
|
|
92
111
|
|
|
93
112
|
def ==(other)
|
|
@@ -96,7 +115,8 @@ module RBS
|
|
|
96
115
|
other.defs == defs &&
|
|
97
116
|
other.accessibility == accessibility &&
|
|
98
117
|
other.annotations == annotations &&
|
|
99
|
-
other.alias_of == alias_of
|
|
118
|
+
other.alias_of == alias_of &&
|
|
119
|
+
other.alias_member == alias_member
|
|
100
120
|
end
|
|
101
121
|
|
|
102
122
|
alias eql? ==
|
|
@@ -127,10 +147,6 @@ module RBS
|
|
|
127
147
|
@comments ||= defs.map(&:comment).compact.uniq
|
|
128
148
|
end
|
|
129
149
|
|
|
130
|
-
def annotations
|
|
131
|
-
@annotations ||= defs.flat_map {|d| d.member_annotations }
|
|
132
|
-
end
|
|
133
|
-
|
|
134
150
|
def members
|
|
135
151
|
@members ||= defs.map(&:member).uniq
|
|
136
152
|
end
|
|
@@ -146,49 +162,42 @@ module RBS
|
|
|
146
162
|
def sub(s)
|
|
147
163
|
return self if s.empty?
|
|
148
164
|
|
|
149
|
-
|
|
165
|
+
update(
|
|
150
166
|
super_method: super_method&.sub(s),
|
|
151
|
-
defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) }
|
|
152
|
-
accessibility: @accessibility,
|
|
153
|
-
alias_of: alias_of
|
|
167
|
+
defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) }
|
|
154
168
|
)
|
|
155
169
|
end
|
|
156
170
|
|
|
157
171
|
def map_type(&block)
|
|
158
|
-
|
|
172
|
+
update(
|
|
159
173
|
super_method: super_method&.map_type(&block),
|
|
160
|
-
defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) }
|
|
161
|
-
accessibility: @accessibility,
|
|
162
|
-
alias_of: alias_of
|
|
174
|
+
defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) }
|
|
163
175
|
)
|
|
164
176
|
end
|
|
165
177
|
|
|
166
178
|
def map_type_bound(&block)
|
|
167
|
-
|
|
179
|
+
update(
|
|
168
180
|
super_method: super_method&.map_type_bound(&block),
|
|
169
|
-
defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) }
|
|
170
|
-
accessibility: @accessibility,
|
|
171
|
-
alias_of: alias_of
|
|
181
|
+
defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) }
|
|
172
182
|
)
|
|
173
183
|
end
|
|
174
184
|
|
|
175
185
|
def map_method_type(&block)
|
|
176
|
-
|
|
177
|
-
super_method: super_method,
|
|
186
|
+
update(
|
|
178
187
|
defs: defs.map {|defn| defn.update(type: yield(defn.type)) },
|
|
179
|
-
accessibility: @accessibility,
|
|
180
|
-
alias_of: alias_of
|
|
181
188
|
)
|
|
182
189
|
end
|
|
183
190
|
|
|
184
|
-
def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations)
|
|
191
|
+
def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations, alias_member: self.alias_member)
|
|
185
192
|
self.class.new(
|
|
186
193
|
super_method: super_method,
|
|
187
194
|
defs: defs,
|
|
188
195
|
accessibility: accessibility,
|
|
189
196
|
alias_of: alias_of,
|
|
190
|
-
|
|
191
|
-
)
|
|
197
|
+
alias_member: alias_member
|
|
198
|
+
).tap do |method|
|
|
199
|
+
method.annotations.replace(annotations)
|
|
200
|
+
end
|
|
192
201
|
end
|
|
193
202
|
end
|
|
194
203
|
|
|
@@ -217,6 +217,7 @@ module RBS
|
|
|
217
217
|
NoSuperclassFoundError.check!(super_name, env: env, location: primary.decl.location)
|
|
218
218
|
if super_class
|
|
219
219
|
InheritModuleError.check!(super_class, env: env)
|
|
220
|
+
InvalidTypeApplicationError.check2!(type_name: super_class.name, args: super_class.args, env: env, location: super_class.location)
|
|
220
221
|
end
|
|
221
222
|
|
|
222
223
|
super_entry = env.normalized_class_entry(super_name) or raise
|
|
@@ -243,6 +244,7 @@ module RBS
|
|
|
243
244
|
else
|
|
244
245
|
entry.self_types.each do |module_self|
|
|
245
246
|
NoSelfTypeFoundError.check!(module_self, env: env)
|
|
247
|
+
InvalidTypeApplicationError.check2!(type_name: module_self.name, args: module_self.args, env: env, location: module_self.location)
|
|
246
248
|
|
|
247
249
|
module_name = module_self.name
|
|
248
250
|
if module_name.class?
|