Skip to content

Commit 471a0e2

Browse files
committed
[CursorInfo] Fix issues found by the stress tester
1 parent 1903497 commit 471a0e2

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
}
@@ -367,10 +369,12 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
367369

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

375379
if (Callback.getResults().empty()) {
376380
// No results.
@@ -388,6 +392,11 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
388392
SmallVector<ResolvedCursorInfoPtr> Results;
389393
for (auto Res : Callback.getResults()) {
390394
SmallVector<NominalTypeDecl *> ReceiverTypes;
395+
if (isa<ModuleDecl>(Res.ReferencedDecl)) {
396+
// ResolvedModuleRefCursorInfo is not supported by solver-based cursor
397+
// info yet.
398+
continue;
399+
}
391400
if (Res.IsDynamicRef && Res.BaseType) {
392401
if (auto ReceiverType = Res.BaseType->getAnyNominal()) {
393402
ReceiverTypes = {ReceiverType};
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)