Skip to content

Commit 89e0f45

Browse files
committed
[Result Builders] Correct type witness substitution when computing inferred
result builder attributes from protocol requirements.
1 parent ba2187a commit 89e0f45

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,11 @@ static Type inferResultBuilderType(ValueDecl *decl) {
297297
if (witness != lookupDecl)
298298
continue;
299299

300-
// Substitute into the result builder type.
301-
auto subs =
302-
conformance->getSubstitutions(lookupDecl->getModuleContext());
300+
// Substitute Self and associated type witnesses into the
301+
// result builder type.
302+
auto subs = SubstitutionMap::getProtocolSubstitutions(
303+
protocol, dc->getSelfTypeInContext(),
304+
ProtocolConformanceRef(conformance));
303305
Type subResultBuilderType = resultBuilderType.subst(subs);
304306

305307
matches.push_back(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
2+
3+
protocol P {
4+
associatedtype A
5+
6+
@Builder<A>
7+
var x1: [S] { get }
8+
9+
@Builder<Self>
10+
var x2: [S] { get }
11+
}
12+
13+
@resultBuilder
14+
enum Builder<T> {
15+
static func buildBlock(_ args: S...) -> [S] { args }
16+
}
17+
18+
struct S {}
19+
20+
// CHECK: struct_decl{{.*}}TestGenericBuilderInference
21+
struct TestGenericBuilderInference: P {
22+
typealias A = Int
23+
24+
// CHECK: var_decl{{.*}}x1
25+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> Int))
26+
var x1: [S] { S() }
27+
28+
// CHECK: var_decl{{.*}}x2
29+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> TestGenericBuilderInference))
30+
var x2: [S] { S() }
31+
}

0 commit comments

Comments
 (0)