@@ -56,14 +56,14 @@ static void check_children_cap(rbs_loc *loc) {
5656 }
5757}
5858
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 ) {
6060 rbs_loc_add_optional_child (loc , name , r );
6161
6262 unsigned short last_index = loc -> children -> len - 1 ;
6363 loc -> children -> required_p |= 1 << last_index ;
6464}
6565
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 ) {
6767 check_children_cap (loc );
6868
6969 unsigned short i = loc -> children -> len ++ ;
@@ -168,14 +168,20 @@ static VALUE location_end_pos(VALUE self) {
168168 return INT2FIX (loc -> rg .end );
169169}
170170
171+ static rbs_constant_id_t rbs_find_constant_id_from_ruby_symbol (VALUE symbol ) {
172+ VALUE name = rb_sym2str (symbol );
173+
174+ return rbs_constant_pool_find (RBS_GLOBAL_CONSTANT_POOL , (const uint8_t * ) RSTRING_PTR (name ), RSTRING_LEN (name ));
175+ }
176+
171177static VALUE location_add_required_child (VALUE self , VALUE name , VALUE start , VALUE end ) {
172178 rbs_loc * loc = rbs_check_location (self );
173179
174180 range rg ;
175181 rg .start = rbs_loc_position (FIX2INT (start ));
176182 rg .end = rbs_loc_position (FIX2INT (end ));
177183
178- rbs_loc_add_required_child (loc , SYM2ID (name ), rg );
184+ rbs_loc_add_required_child (loc , rbs_find_constant_id_from_ruby_symbol (name ), rg );
179185
180186 return Qnil ;
181187}
@@ -187,15 +193,15 @@ static VALUE location_add_optional_child(VALUE self, VALUE name, VALUE start, VA
187193 rg .start = rbs_loc_position (FIX2INT (start ));
188194 rg .end = rbs_loc_position (FIX2INT (end ));
189195
190- rbs_loc_add_optional_child (loc , SYM2ID (name ), rg );
196+ rbs_loc_add_optional_child (loc , rbs_find_constant_id_from_ruby_symbol (name ), rg );
191197
192198 return Qnil ;
193199}
194200
195201static VALUE location_add_optional_no_child (VALUE self , VALUE name ) {
196202 rbs_loc * loc = rbs_check_location (self );
197203
198- rbs_loc_add_optional_child (loc , SYM2ID (name ), NULL_RANGE );
204+ rbs_loc_add_optional_child (loc , rbs_find_constant_id_from_ruby_symbol (name ), NULL_RANGE );
199205
200206 return Qnil ;
201207}
@@ -221,9 +227,9 @@ static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
221227static VALUE location_aref (VALUE self , VALUE name ) {
222228 rbs_loc * loc = rbs_check_location (self );
223229
224- ID id = SYM2ID (name );
230+ rbs_constant_id_t id = rbs_find_constant_id_from_ruby_symbol (name );
225231
226- if (loc -> children != NULL ) {
232+ if (loc -> children != NULL && id != RBS_CONSTANT_ID_UNSET ) {
227233 for (unsigned short i = 0 ; i < loc -> children -> len ; i ++ ) {
228234 if (loc -> children -> entries [i ].name == id ) {
229235 rbs_loc_range result = loc -> children -> entries [i ].rg ;
@@ -241,6 +247,11 @@ static VALUE location_aref(VALUE self, VALUE name) {
241247 rb_raise (rb_eRuntimeError , "Unknown child name given: %s" , RSTRING_PTR (string ));
242248}
243249
250+ static VALUE rbs_constant_to_ruby_symbol (rbs_constant_t * constant ) {
251+ // Casts back the Ruby Symbol that was inserted by `rbs_constant_pool_insert_constant()`.
252+ return (VALUE ) constant ;
253+ }
254+
244255static VALUE location_optional_keys (VALUE self ) {
245256 VALUE keys = rb_ary_new ();
246257
@@ -252,8 +263,9 @@ static VALUE location_optional_keys(VALUE self) {
252263
253264 for (unsigned short i = 0 ; i < children -> len ; i ++ ) {
254265 if (RBS_LOC_OPTIONAL_P (loc , i )) {
255- rb_ary_push (keys , ID2SYM (children -> entries [i ].name ));
256-
266+ rbs_constant_t * key_id = rbs_constant_pool_id_to_constant (RBS_GLOBAL_CONSTANT_POOL , children -> entries [i ].name );
267+ VALUE key_sym = rbs_constant_to_ruby_symbol (key_id );
268+ rb_ary_push (keys , key_sym );
257269 }
258270 }
259271
@@ -271,7 +283,9 @@ static VALUE location_required_keys(VALUE self) {
271283
272284 for (unsigned short i = 0 ; i < children -> len ; i ++ ) {
273285 if (RBS_LOC_REQUIRED_P (loc , i )) {
274- rb_ary_push (keys , ID2SYM (children -> entries [i ].name ));
286+ rbs_constant_t * key_id = rbs_constant_pool_id_to_constant (RBS_GLOBAL_CONSTANT_POOL , children -> entries [i ].name );
287+ VALUE key_sym = rbs_constant_to_ruby_symbol (key_id );
288+ rb_ary_push (keys , key_sym );
275289 }
276290 }
277291
0 commit comments