Skip to content

Commit 13f47b6

Browse files
committed
[CursorInfo] Fix issues found by the stress tester
1 parent 04a73b2 commit 13f47b6

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

lib/IDE/CursorInfo.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ class NodeFinder : ASTWalker {
219219
if (auto CaptureList = dyn_cast<CaptureListExpr>(E)) {
220220
for (auto ShorthandShadows :
221221
getShorthandShadows(CaptureList, getCurrentDeclContext())) {
222-
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0);
222+
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0 ||
223+
ShorthandShadowedDecls[ShorthandShadows.first] ==
224+
ShorthandShadows.second);
223225
ShorthandShadowedDecls[ShorthandShadows.first] =
224226
ShorthandShadows.second;
225227
}
@@ -374,10 +376,12 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
374376

375377
// Type check the statemnt containing E and listen for solutions.
376378
CursorInfoTypeCheckSolutionCallback Callback(*DC, RequestedLoc);
377-
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
378-
DC->getASTContext().SolutionCallback, &Callback);
379-
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
380-
E->getLoc());
379+
{
380+
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
381+
DC->getASTContext().SolutionCallback, &Callback);
382+
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
383+
E->getLoc());
384+
}
381385

382386
if (Callback.getResults().empty()) {
383387
// No results.
@@ -395,6 +399,11 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
395399
SmallVector<ResolvedCursorInfoPtr> Results;
396400
for (auto Res : Callback.getResults()) {
397401
SmallVector<NominalTypeDecl *> ReceiverTypes;
402+
if (isa<ModuleDecl>(Res.ReferencedDecl)) {
403+
// ResolvedModuleRefCursorInfo is not supported by solver-based cursor
404+
// info yet.
405+
continue;
406+
}
398407
if (Res.IsDynamicRef && Res.BaseType) {
399408
if (auto ReceiverType = Res.BaseType->getAnyNominal()) {
400409
ReceiverTypes = {ReceiverType};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Should not crash
16+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):56 %s -- %s
17+
MavigationLink(destination: PeopleDetail(peopleId: people))
18+
}
19+
}
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)