Skip to content

Commit a5101fa

Browse files
committed
[CursorInfo] Fix issues found by the stress tester
1 parent f9532d8 commit a5101fa

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

lib/IDE/CursorInfo.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ class NodeFinder : ASTWalker {
212212
if (auto CaptureList = dyn_cast<CaptureListExpr>(E)) {
213213
for (auto ShorthandShadows :
214214
getShorthandShadows(CaptureList, getCurrentDeclContext())) {
215-
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0);
215+
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0 ||
216+
ShorthandShadowedDecls[ShorthandShadows.first] ==
217+
ShorthandShadows.second);
216218
ShorthandShadowedDecls[ShorthandShadows.first] =
217219
ShorthandShadows.second;
218220
}
@@ -365,10 +367,12 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
365367

366368
// Type check the statemnt containing E and listen for solutions.
367369
CursorInfoTypeCheckSolutionCallback Callback(*SrcFile, RequestedLoc);
368-
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
369-
DC->getASTContext().SolutionCallback, &Callback);
370-
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
371-
E->getLoc());
370+
{
371+
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
372+
DC->getASTContext().SolutionCallback, &Callback);
373+
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
374+
E->getLoc());
375+
}
372376

373377
if (Callback.getResults().empty()) {
374378
// No results.
@@ -385,6 +389,11 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
385389

386390
SmallVector<ResolvedCursorInfoPtr> Results;
387391
for (auto Res : Callback.getResults()) {
392+
if (isa<ModuleDecl>(Res.ReferencedDecl)) {
393+
// ResolvedModuleRefCursorInfo is not supported by solver-based cursor
394+
// info yet.
395+
continue;
396+
}
388397
ResolvedValueRefCursorInfoPtr CursorInfo = new ResolvedValueRefCursorInfo(
389398
new ResolvedCursorInfo(SrcFile), Res.ReferencedDecl,
390399
/*CtorTyRef=*/nullptr,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct GorEach<Data, Content> {
2+
public init(_ data: Data, content: (Data) -> Void) {}
3+
}
4+
5+
struct MavigationLink<Label, Destination> {
6+
init(destination: PeopleDetail) {}
7+
}
8+
9+
struct PeopleDetail {
10+
init(peopleId: Int) {}
11+
}
12+
13+
func test(peoples: [Int]) {
14+
GorEach(peoples) { people in
15+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):56 %s -- %s
16+
MavigationLink(destination: PeopleDetail(peopleId: people))
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Items {
2+
func test() {
3+
// Should not crash
4+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s
5+
_ = Invalid.sink { [weak self] items in
6+
}
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
func test() {
2+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):3 %s -- %s | %FileCheck %s
3+
Swift.min
4+
}
5+
6+
// CHECK: source.lang.swift.ref.module ()
7+
// CHECK-NEXT: Swift

0 commit comments

Comments
 (0)