From a30bbd745c3a1eca6815729ac00e4c73c7a762a2 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Mon, 1 Aug 2022 09:05:12 +0800 Subject: [PATCH 1/3] fix: Fix crash when inheriting from class defined in untyped code. Encountered when indexing Homebrew/brew. --- scip_indexer/SCIPIndexer.cc | 14 +++++++++++--- .../multifile/typed-false-mix/def_untyped.rb | 4 ++++ .../typed-false-mix/def_untyped.snapshot.rb | 5 +++++ .../multifile/typed-false-mix/use_untyped.rb | 8 ++++++++ .../typed-false-mix/use_untyped.snapshot.rb | 11 +++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/scip/testdata/multifile/typed-false-mix/def_untyped.rb create mode 100644 test/scip/testdata/multifile/typed-false-mix/def_untyped.snapshot.rb create mode 100644 test/scip/testdata/multifile/typed-false-mix/use_untyped.rb create mode 100644 test/scip/testdata/multifile/typed-false-mix/use_untyped.snapshot.rb diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index e1c4acbca7..7fa037ea34 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -912,9 +912,17 @@ class CFGTraversal final { isMethodFileStaticInit || method == gs.lookupStaticInitForClass(namedSym.asSymbolRef().asClassOrModuleRef().data(gs)->owner, /*allowMissing*/ true); - ENFORCE(check); - auto status = this->scipState.saveDefinition(gs, file, namedSym, arg.loc); - ENFORCE(status.ok()); + absl::Status status; + string kind; + if (check) { + status = this->scipState.saveDefinition(gs, file, namedSym, arg.loc); + kind = "definition"; + } else { + status = this->scipState.saveReference(gs, file, namedSym, arg.loc, 0); + kind = "reference"; + } + ENFORCE(status.ok(), "failed to save {} for {}\ncontext:\ninstruction: {}\nlocation: {}\n", kind, + namedSym.showRaw(gs), binding.value.showRaw(gs, cfg), core::Loc(file, arg.loc).showRaw(gs)); return true; }; diff --git a/test/scip/testdata/multifile/typed-false-mix/def_untyped.rb b/test/scip/testdata/multifile/typed-false-mix/def_untyped.rb new file mode 100644 index 0000000000..7d4744202b --- /dev/null +++ b/test/scip/testdata/multifile/typed-false-mix/def_untyped.rb @@ -0,0 +1,4 @@ +# typed: false + +class C +end diff --git a/test/scip/testdata/multifile/typed-false-mix/def_untyped.snapshot.rb b/test/scip/testdata/multifile/typed-false-mix/def_untyped.snapshot.rb new file mode 100644 index 0000000000..7745409085 --- /dev/null +++ b/test/scip/testdata/multifile/typed-false-mix/def_untyped.snapshot.rb @@ -0,0 +1,5 @@ + # typed: false + + class C +# ^ definition [..] C# + end diff --git a/test/scip/testdata/multifile/typed-false-mix/use_untyped.rb b/test/scip/testdata/multifile/typed-false-mix/use_untyped.rb new file mode 100644 index 0000000000..4266300759 --- /dev/null +++ b/test/scip/testdata/multifile/typed-false-mix/use_untyped.rb @@ -0,0 +1,8 @@ +# typed: true + +require 'def_untyped' + +module N + class D < C + end +end diff --git a/test/scip/testdata/multifile/typed-false-mix/use_untyped.snapshot.rb b/test/scip/testdata/multifile/typed-false-mix/use_untyped.snapshot.rb new file mode 100644 index 0000000000..a1e2e79eaa --- /dev/null +++ b/test/scip/testdata/multifile/typed-false-mix/use_untyped.snapshot.rb @@ -0,0 +1,11 @@ + # typed: true + + require 'def_untyped' + + module N +# ^ definition [..] N# + class D < C +# ^ definition [..] N#D# +# ^ reference [..] C# + end + end From a05290c1b52e34b7ecef2a7ba3fe9cb4cacc3e43 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Mon, 1 Aug 2022 09:40:06 +0800 Subject: [PATCH 2/3] Update scip_indexer/SCIPIndexer.cc --- scip_indexer/SCIPIndexer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index 7fa037ea34..23851a831a 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -918,7 +918,7 @@ class CFGTraversal final { status = this->scipState.saveDefinition(gs, file, namedSym, arg.loc); kind = "definition"; } else { - status = this->scipState.saveReference(gs, file, namedSym, arg.loc, 0); + status = this->scipState.saveReference(gs, file, namedSym, arg.loc, referenceRole); kind = "reference"; } ENFORCE(status.ok(), "failed to save {} for {}\ncontext:\ninstruction: {}\nlocation: {}\n", kind, From 05a76e3a0c0e750ec3119c6cbf37a024a1e4c92b Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Mon, 1 Aug 2022 09:42:57 +0800 Subject: [PATCH 3/3] Update scip_indexer/SCIPIndexer.cc --- scip_indexer/SCIPIndexer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index 23851a831a..7fa037ea34 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -918,7 +918,7 @@ class CFGTraversal final { status = this->scipState.saveDefinition(gs, file, namedSym, arg.loc); kind = "definition"; } else { - status = this->scipState.saveReference(gs, file, namedSym, arg.loc, referenceRole); + status = this->scipState.saveReference(gs, file, namedSym, arg.loc, 0); kind = "reference"; } ENFORCE(status.ok(), "failed to save {} for {}\ncontext:\ninstruction: {}\nlocation: {}\n", kind,