@@ -230,9 +230,27 @@ class NamedSymbolRef final {
230
230
if (this ->selfOrOwner .isFieldOrStaticField ()) {
231
231
return Kind::StaticField;
232
232
}
233
+ if (this ->selfOrOwner .isMethod ()) {
234
+ return Kind::Method;
235
+ }
233
236
return Kind::ClassOrModule;
234
237
}
235
238
239
+ string showRaw (const core::GlobalState &gs) const {
240
+ switch (this ->kind ()) {
241
+ case Kind::UndeclaredField:
242
+ return fmt::format (" UndeclaredField(owner: {}, name: {})" , this ->selfOrOwner .showFullName (gs),
243
+ this ->name .toString (gs));
244
+ case Kind::StaticField:
245
+ return fmt::format (" StaticField {}" , this ->selfOrOwner .showFullName (gs));
246
+ case Kind::ClassOrModule:
247
+ return fmt::format (" ClassOrModule {}" , this ->selfOrOwner .showFullName (gs));
248
+ case Kind::Method:
249
+ return fmt::format (" Method {}" , this ->selfOrOwner .showFullName (gs));
250
+ }
251
+ ENFORCE (false , " impossible" );
252
+ }
253
+
236
254
core::SymbolRef asSymbolRef () const {
237
255
ENFORCE (this ->kind () != Kind::UndeclaredField);
238
256
return this ->selfOrOwner ;
@@ -578,6 +596,11 @@ class AliasMap final {
578
596
auto &gs = ctx.state ;
579
597
auto method = ctx.owner ;
580
598
auto klass = method.owner (gs);
599
+ // Make sure that the offsets we store here match the offsets we use
600
+ // in saveDefinition/saveReference.
601
+ auto trim = [&](core::LocOffsets loc) -> core::LocOffsets {
602
+ return trimColonColonPrefix (gs, core::Loc (ctx.file , loc)).offsets ();
603
+ };
581
604
for (auto &bb : cfg.basicBlocks ) {
582
605
for (auto &bind : bb->exprs ) {
583
606
auto *instr = cfg::cast_instruction<cfg::Alias>(bind.value );
@@ -592,12 +615,13 @@ class AliasMap final {
592
615
}
593
616
if (sym == core::Symbols::Magic_undeclaredFieldStub ()) {
594
617
ENFORCE (!bind.loc .empty ());
595
- this ->map .insert (
618
+ this ->map .insert ( // no trim(...) because undeclared fields shouldn't have ::
596
619
{bind.bind .variable , {NamedSymbolRef::undeclaredField (klass, instr->name ), bind.loc , false }});
597
620
continue ;
598
621
}
599
622
if (sym.isStaticField (gs)) {
600
- this ->map .insert ({bind.bind .variable , {NamedSymbolRef::staticField (instr->what ), bind.loc , false }});
623
+ this ->map .insert (
624
+ {bind.bind .variable , {NamedSymbolRef::staticField (instr->what ), trim (bind.loc ), false }});
601
625
continue ;
602
626
}
603
627
// Outside of definition contexts for classes & modules,
@@ -614,7 +638,7 @@ class AliasMap final {
614
638
if (!loc.exists () || loc.empty ()) { // For special classes like Sorbet::Private::Static
615
639
continue ;
616
640
}
617
- this ->map .insert ({bind.bind .variable , {NamedSymbolRef::classOrModule (sym), loc, false }});
641
+ this ->map .insert ({bind.bind .variable , {NamedSymbolRef::classOrModule (sym), trim ( loc) , false }});
618
642
}
619
643
}
620
644
}
@@ -954,9 +978,11 @@ class CFGTraversal final {
954
978
}
955
979
}
956
980
// Sort for determinism
957
- fast_sort (todo, [](const SymbolWithLoc &p1, const SymbolWithLoc &p2) -> bool {
981
+ fast_sort (todo, [& ](const SymbolWithLoc &p1, const SymbolWithLoc &p2) -> bool {
958
982
ENFORCE (p1.second .beginPos () != p2.second .beginPos (),
959
- " Different alias instructions should correspond to different start offsets" );
983
+ " found alias instructions with same start offset in {}, source:\n {}\n sym1 = {}, sym2 = {}\n " ,
984
+ file.data (gs).path (), core::Loc (file, p1.second ).toString (gs), p1.first .showRaw (gs),
985
+ p2.first .showRaw (gs));
960
986
return p1.second .beginPos () < p2.second .beginPos ();
961
987
});
962
988
// NOTE:(varun) Not 100% sure if emitting a reference here. Here's why it's written this
0 commit comments