Skip to content

Commit 7302792

Browse files
committed
[IDE] Use method result type for getTypeOfMember call
Previously we were defaulting to the method's interface type, which could lead to calling `subst` with a GenericFunctionType. Instead, pass the result type only, as that's all we want anyway. rdar://77259607
1 parent 08a5c95 commit 7302792

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

lib/IDE/ConformingMethodList.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,20 @@ void ConformingMethodListCallbacks::getMatchingMethods(
129129
/// Returns true if \p VD is a instance method whose return type conforms
130130
/// to the requested protocols.
131131
bool isMatchingMethod(ValueDecl *VD) {
132-
if (!isa<FuncDecl>(VD))
132+
auto *FD = dyn_cast<FuncDecl>(VD);
133+
if (!FD)
133134
return false;
134-
if (VD->isStatic() || VD->isOperator())
135+
if (FD->isStatic() || FD->isOperator())
135136
return false;
136137

137-
auto declTy = T->getTypeOfMember(CurModule, VD);
138-
if (declTy->is<ErrorType>())
138+
auto resultTy = T->getTypeOfMember(CurModule, FD,
139+
FD->getResultInterfaceType());
140+
if (resultTy->is<ErrorType>())
139141
return false;
140142

141-
// Strip '(Self.Type) ->' and parameters.
142-
declTy = declTy->castTo<AnyFunctionType>()->getResult();
143-
declTy = declTy->castTo<AnyFunctionType>()->getResult();
144-
145143
// The return type conforms to any of the requested protocols.
146144
for (auto Proto : ExpectedTypes) {
147-
if (CurModule->conformsToProtocol(declTy, Proto))
145+
if (CurModule->conformsToProtocol(resultTy, Proto))
148146
return true;
149147
}
150148

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-ide-test -conforming-methods -source-filename %s -code-completion-token=CM1 -module-name MyModule -conforming-methods-expected-types '$s8MyModule6TargetPD' | %FileCheck %s -check-prefix=SI
2+
// RUN: %target-swift-ide-test -conforming-methods -source-filename %s -code-completion-token=CM2 -module-name MyModule -conforming-methods-expected-types '$s8MyModule6TargetPD' | %FileCheck %s -check-prefix=SF
3+
4+
protocol Target {}
5+
struct Concrete : Target {}
6+
7+
struct S<T> {
8+
func returnsAnything<U>() -> U { fatalError() }
9+
}
10+
11+
extension S where T == Int {
12+
func returnsConcrete<U>(_ x: U) -> Concrete { fatalError() }
13+
}
14+
15+
func test(si: S<Int>, sf: S<Float>) {
16+
si.#^CM1^#
17+
// SI: -----BEGIN CONFORMING METHOD LIST-----
18+
// SI-NEXT: - TypeName: S<Int>
19+
// SI-NEXT: - Members:
20+
// SI-NEXT: - Name: returnsConcrete(_:)
21+
// SI-NEXT: TypeName: Concrete
22+
// SI-NEXT: -----END CONFORMING METHOD LIST-----
23+
24+
sf.#^CM2^#
25+
// SF: -----BEGIN CONFORMING METHOD LIST-----
26+
// SF-NEXT: - TypeName: S<Float>
27+
// SF-NEXT: - Members: []
28+
// SF-NEXT: -----END CONFORMING METHOD LIST-----
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-ide-test -conforming-methods -source-filename %s -code-completion-token=CC
2+
3+
protocol MyView {}
4+
5+
extension MyView {
6+
func foo<Content>() -> Content? {
7+
return nil#^CC^#
8+
}
9+
}

0 commit comments

Comments
 (0)