Skip to content

Commit a9cba54

Browse files
committed
[CursorInfo] Fix a bug that caused solver-based cursor info to crash if invoked on a symbol from a different module
1 parent 3e46063 commit a9cba54

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/IDE/CursorInfo.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ void typeCheckDeclAndParentClosures(ValueDecl *VD) {
4848
DC = DC->getParent();
4949
}
5050

51-
typeCheckASTNodeAtLoc(
52-
TypeCheckASTNodeAtLocContext::declContext(VD->getDeclContext()),
53-
VD->getLoc());
51+
if (!VD->getInterfaceType()) {
52+
// The decl has an interface time if it came from another module. In that
53+
// case, there's nothing to do. Otherwise, type check the decl to get its
54+
// type.
55+
typeCheckASTNodeAtLoc(
56+
TypeCheckASTNodeAtLocContext::declContext(VD->getDeclContext()),
57+
VD->getLoc());
58+
}
5459
if (auto VarD = dyn_cast<VarDecl>(VD)) {
5560
if (VarD->hasAttachedPropertyWrapper()) {
5661
// Type check any attached property wrappers so the annotated declaration

lib/IDE/SelectedOverloadInfo.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ swift::ide::getSelectedOverloadInfo(const Solution &S,
3636
if (Result.BaseTy) {
3737
Result.BaseTy = S.simplifyType(Result.BaseTy)->getRValueType();
3838
}
39+
if (Result.BaseTy && Result.BaseTy->is<ModuleType>()) {
40+
Result.BaseTy = nullptr;
41+
}
3942

4043
Result.Value = SelectedOverload->choice.getDeclOrNull();
4144
Result.ValueTy =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
func test() {
2+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s | %FileCheck %s
3+
Swift.min(1, 2)
4+
}
5+
6+
// CHECK: source.lang.swift.ref.function.free ()
7+
// CHECK-NEXT: min(_:_:)
8+
// CHECK-NEXT: s:s3minyxx_xtSLRzlF
9+
// CHECK-NEXT: source.lang.swift
10+
// CHECK-NEXT: <T where T : Comparable> (T, T) -> T
11+
// CHECK-NEXT: $syxx_xtcSLRzluD
12+
// CHECK-NEXT: Swift

0 commit comments

Comments
 (0)