Skip to content

Commit faf2bcc

Browse files
Sema: Resolve result builder type in innermost decl context
1 parent 50f8123 commit faf2bcc

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ Type ResultBuilderTypeRequest::evaluate(Evaluator &evaluator,
379379

380380
// Resolve a type for the attribute.
381381
auto mutableAttr = const_cast<CustomAttr*>(attr);
382-
auto dc = decl->getDeclContext();
382+
auto *dc = decl->getInnermostDeclContext();
383383
auto &ctx = dc->getASTContext();
384384
Type type = evaluateOrDefault(
385385
evaluator,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// No warnings.
2+
// RUN: %target-typecheck-verify-swift
3+
//
4+
// RUN: %target-run-simple-swift | %FileCheck %s
5+
//
6+
// REQUIRES: executable_test
7+
8+
@resultBuilder
9+
struct Builder<T> {
10+
static func buildBlock(_ args: T...) -> [T] { args }
11+
}
12+
13+
// https://github.com/swiftlang/swift/issues/72739
14+
do {
15+
@Builder<T>
16+
func buildArray<T>(_ t1: T, _ t2: T, _ t3: T) -> [T] {
17+
t1
18+
t2
19+
t3
20+
}
21+
22+
enum TypeContext {
23+
@Builder<T>
24+
static func buildArray<T>(_ t1: T, _ t2: T, _ t3: T) -> [T] {
25+
t1
26+
t2
27+
t3
28+
}
29+
}
30+
31+
// CHECK: begin
32+
print("begin")
33+
// CHECK-NEXT: [1, 2, 3]
34+
print(buildArray(1, 2, 3))
35+
// CHECK-NEXT: [1, 2, 3]
36+
print(TypeContext.buildArray(1, 2, 3))
37+
// CHECK-NEXT: end
38+
print("end")
39+
}
40+

0 commit comments

Comments
 (0)