Skip to content

fix: Fix crash with duplicate alias locs. #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions scip_indexer/SCIPIndexer.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// NOTE: Protobuf headers should go first since they use poisoned functions.
#include "proto/SCIP.pb.h"

#include <algorithm>
#include <fstream>
#include <iterator>
#include <memory>
Expand Down Expand Up @@ -977,14 +978,25 @@ class CFGTraversal final {
todo.emplace_back(namedSym, loc);
}
}
bool foundDupes = false;
// Sort for determinism
fast_sort(todo, [&](const SymbolWithLoc &p1, const SymbolWithLoc &p2) -> bool {
ENFORCE(p1.second.beginPos() != p2.second.beginPos(),
"found alias instructions with same start offset in {}, source:\n{}\nsym1 = {}, sym2 = {}\n",
file.data(gs).path(), core::Loc(file, p1.second).toString(gs), p1.first.showRaw(gs),
p2.first.showRaw(gs));
if (p1.second.beginPos() == p2.second.beginPos()) {
// TODO: This code path is hit when there is a module_function on top of a sig.
// In that case, the 'T' and 'X' in 'T::X' in a sig end up with two occurrences each.
// We should check if this is a Sorbet bug or deliberate.
ENFORCE(p1.first == p2.first,
"found different symbols at same location in {}, source:\n{}\nsym1 = {}\nsym2 = {}\n",
file.data(gs).path(), core::Loc(file, p1.second).toString(gs), p1.first.showRaw(gs),
p2.first.showRaw(gs));
foundDupes = true;
}
return p1.second.beginPos() < p2.second.beginPos();
});
if (foundDupes) {
auto last = unique(todo.begin(), todo.end());
todo.erase(last, todo.end());
}
// NOTE:(varun) Not 100% sure if emitting a reference here. Here's why it's written this
// way right now. This code path is hit in two different kinds of situations:
// - You have a reference to a nested class etc. inside a method body.
Expand Down
8 changes: 8 additions & 0 deletions test/scip/testdata/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
def f()
T.let(true, T::Boolean)
end

module M
module_function
sig { returns(T::Boolean) }
def b
true
end
end
18 changes: 18 additions & 0 deletions test/scip/testdata/types.snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@ def f()
# ^ reference scip-ruby gem TODO TODO T#
# ^^^^^^^ reference scip-ruby gem TODO TODO T#Boolean.
end

module M
# ^ definition scip-ruby gem TODO TODO M#
module_function
sig { returns(T::Boolean) }
# ^^^ reference scip-ruby gem TODO TODO Sorbet#Private#Static#<Class:ResolvedSig>#sig().
# ^^^ reference scip-ruby gem TODO TODO Sorbet#Private#Static#<Class:ResolvedSig>#sig().
# ^ reference scip-ruby gem TODO TODO T#
# ^^^^^^^ reference scip-ruby gem TODO TODO T#Boolean.
# ^^^^^^^ reference scip-ruby gem TODO TODO T#Boolean.
# ^^^^^^^^^^ reference scip-ruby gem TODO TODO Sorbet#Private#Static#ResolvedSig#
# ^^^^^^^^^^ reference scip-ruby gem TODO TODO Sorbet#Private#Static#ResolvedSig#
def b
# ^^^^^ definition scip-ruby gem TODO TODO M#b().
# ^^^^^ definition scip-ruby gem TODO TODO <Class:M>#b().
true
end
end