Skip to content

Commit 5b64e6c

Browse files
authored
Merge pull request #2256 from Shopify/at-remove-unchecked-call
Remove call to `TypeParam#unchecked!` from C parser
2 parents 00d9e1f + 6d2348e commit 5b64e6c

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ nodes:
191191
- name: variance
192192
- name: upper_bound
193193
- name: default_type
194+
- name: unchecked
194195
- name: location
195196
- name: RBS::MethodType
196197
fields:

ext/rbs_extension/parser.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
11581158
rg->start = state->current_token.range.start;
11591159

11601160
while (true) {
1161-
bool unchecked = false;
1161+
VALUE unchecked = Qfalse;
11621162
VALUE variance = ID2SYM(rb_intern("invariant"));
11631163
VALUE upper_bound = Qnil;
11641164
VALUE default_type = Qnil;
@@ -1170,7 +1170,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
11701170
range unchecked_range = NULL_RANGE;
11711171
if (module_type_params) {
11721172
if (state->next_token.type == kUNCHECKED) {
1173-
unchecked = true;
1173+
unchecked = Qtrue;
11741174
parser_advance(state);
11751175
unchecked_range = state->current_token.range;
11761176
}
@@ -1245,11 +1245,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
12451245
rbs_loc_add_optional_child(loc, INTERN("upper_bound"), upper_bound_range);
12461246
rbs_loc_add_optional_child(loc, INTERN("default"), default_type_range);
12471247

1248-
VALUE param = rbs_ast_type_param(name, variance, upper_bound, default_type, location);
1249-
1250-
if (unchecked) {
1251-
rb_funcall(param, rb_intern("unchecked!"), 0);
1252-
}
1248+
VALUE param = rbs_ast_type_param(name, variance, upper_bound, default_type, unchecked, location);
12531249

12541250
melt_array(&params);
12551251
rb_ary_push(params, param);

include/rbs/ruby_objs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method
3939
VALUE rbs_ast_members_prepend(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
4040
VALUE rbs_ast_members_private(VALUE location);
4141
VALUE rbs_ast_members_public(VALUE location);
42-
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE location);
42+
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location);
4343
VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
4444
VALUE rbs_namespace(VALUE path, VALUE absolute);
4545
VALUE rbs_type_name(VALUE namespace, VALUE name);

lib/rbs/ast/type_param.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module AST
55
class TypeParam
66
attr_reader :name, :variance, :location, :upper_bound_type, :default_type
77

8-
def initialize(name:, variance:, upper_bound:, location:, default_type: nil)
8+
def initialize(name:, variance:, upper_bound:, location:, default_type: nil, unchecked: false)
99
@name = name
1010
@variance = variance
1111
@upper_bound_type = upper_bound
1212
@location = location
13-
@unchecked = false
1413
@default_type = default_type
14+
@unchecked = unchecked
1515
end
1616

1717
def upper_bound

sig/type_param.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module RBS
2626

2727
attr_reader default_type: Types::t?
2828

29-
def initialize: (name: Symbol, variance: variance, upper_bound: Types::t?, location: loc?, ?default_type: Types::t?) -> void
29+
def initialize: (name: Symbol, variance: variance, upper_bound: Types::t?, location: loc?, ?default_type: Types::t?, ?unchecked: bool) -> void
3030

3131
include _ToJson
3232

src/ruby_objs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,13 @@ VALUE rbs_ast_members_public(VALUE location) {
435435
);
436436
}
437437

438-
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE location) {
438+
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location) {
439439
VALUE _init_kwargs = rb_hash_new();
440440
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), name);
441441
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("variance")), variance);
442442
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("upper_bound")), upper_bound);
443443
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("default_type")), default_type);
444+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("unchecked")), unchecked);
444445
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
445446

446447
return CLASS_NEW_INSTANCE(

0 commit comments

Comments
 (0)