@@ -56,14 +56,14 @@ static void check_children_cap(rbs_loc *loc) {
56
56
}
57
57
}
58
58
59
- void rbs_loc_add_required_child (rbs_loc * loc , ID name , range r ) {
59
+ void rbs_loc_add_required_child (rbs_loc * loc , rbs_constant_id_t name , range r ) {
60
60
rbs_loc_add_optional_child (loc , name , r );
61
61
62
62
unsigned short last_index = loc -> children -> len - 1 ;
63
63
loc -> children -> required_p |= 1 << last_index ;
64
64
}
65
65
66
- void rbs_loc_add_optional_child (rbs_loc * loc , ID name , range r ) {
66
+ void rbs_loc_add_optional_child (rbs_loc * loc , rbs_constant_id_t name , range r ) {
67
67
check_children_cap (loc );
68
68
69
69
unsigned short i = loc -> children -> len ++ ;
@@ -168,14 +168,31 @@ static VALUE location_end_pos(VALUE self) {
168
168
return INT2FIX (loc -> rg .end );
169
169
}
170
170
171
+ static rbs_constant_id_t rbs_constant_id_from_ruby_symbol (VALUE symbol ) {
172
+ const char * name = rb_id2name (SYM2ID (symbol ));
173
+
174
+ if (name == NULL ) {
175
+ // This happens if `symbol` was a Dynamic symbol (as opposed to a "static symbol" which has
176
+ // been interned to get a an ID).
177
+ return RBS_CONSTANT_ID_UNSET ;
178
+ }
179
+
180
+ return rbs_constant_pool_find (RBS_GLOBAL_CONSTANT_POOL , (const uint8_t * ) name , strlen (name ));
181
+ }
182
+
183
+ static VALUE rbs_constant_to_ruby_symbol (rbs_constant_t * constant ) {
184
+ // Casts back the symbol that was looked up by `pm_constant_pool_id_to_constant()`.
185
+ return (VALUE ) constant ;
186
+ }
187
+
171
188
static VALUE location_add_required_child (VALUE self , VALUE name , VALUE start , VALUE end ) {
172
189
rbs_loc * loc = rbs_check_location (self );
173
190
174
191
range rg ;
175
192
rg .start = rbs_loc_position (FIX2INT (start ));
176
193
rg .end = rbs_loc_position (FIX2INT (end ));
177
194
178
- rbs_loc_add_required_child (loc , SYM2ID (name ), rg );
195
+ rbs_loc_add_required_child (loc , rbs_constant_id_from_ruby_symbol (name ), rg );
179
196
180
197
return Qnil ;
181
198
}
@@ -187,15 +204,15 @@ static VALUE location_add_optional_child(VALUE self, VALUE name, VALUE start, VA
187
204
rg .start = rbs_loc_position (FIX2INT (start ));
188
205
rg .end = rbs_loc_position (FIX2INT (end ));
189
206
190
- rbs_loc_add_optional_child (loc , SYM2ID (name ), rg );
207
+ rbs_loc_add_optional_child (loc , rbs_constant_id_from_ruby_symbol (name ), rg );
191
208
192
209
return Qnil ;
193
210
}
194
211
195
212
static VALUE location_add_optional_no_child (VALUE self , VALUE name ) {
196
213
rbs_loc * loc = rbs_check_location (self );
197
214
198
- rbs_loc_add_optional_child (loc , SYM2ID (name ), NULL_RANGE );
215
+ rbs_loc_add_optional_child (loc , rbs_constant_id_from_ruby_symbol (name ), NULL_RANGE );
199
216
200
217
return Qnil ;
201
218
}
@@ -221,9 +238,9 @@ static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
221
238
static VALUE location_aref (VALUE self , VALUE name ) {
222
239
rbs_loc * loc = rbs_check_location (self );
223
240
224
- ID id = SYM2ID (name );
241
+ rbs_constant_id_t id = rbs_constant_id_from_ruby_symbol (name );
225
242
226
- if (loc -> children != NULL ) {
243
+ if (loc -> children != NULL && id != RBS_CONSTANT_ID_UNSET ) {
227
244
for (unsigned short i = 0 ; i < loc -> children -> len ; i ++ ) {
228
245
if (loc -> children -> entries [i ].name == id ) {
229
246
rbs_loc_range result = loc -> children -> entries [i ].rg ;
@@ -252,8 +269,8 @@ static VALUE location_optional_keys(VALUE self) {
252
269
253
270
for (unsigned short i = 0 ; i < children -> len ; i ++ ) {
254
271
if (RBS_LOC_OPTIONAL_P (loc , i )) {
255
- rb_ary_push ( keys , ID2SYM ( children -> entries [i ].name ) );
256
-
272
+ rbs_constant_t * key = rbs_constant_pool_id_to_constant ( RBS_GLOBAL_CONSTANT_POOL , children -> entries [i ].name );
273
+ rb_ary_push ( keys , rbs_constant_to_ruby_symbol ( key ));
257
274
}
258
275
}
259
276
@@ -271,7 +288,8 @@ static VALUE location_required_keys(VALUE self) {
271
288
272
289
for (unsigned short i = 0 ; i < children -> len ; i ++ ) {
273
290
if (RBS_LOC_REQUIRED_P (loc , i )) {
274
- rb_ary_push (keys , ID2SYM (children -> entries [i ].name ));
291
+ rbs_constant_t * key = rbs_constant_pool_id_to_constant (RBS_GLOBAL_CONSTANT_POOL , children -> entries [i ].name );
292
+ rb_ary_push (keys , rbs_constant_to_ruby_symbol (key ));
275
293
}
276
294
}
277
295
0 commit comments