Sema: Resolve result builder type in innermost decl context

This commit is contained in:
Anthony Latsis
2024-09-10 04:44:21 +03:00
committed by GitHub
parent 50f81234f1
commit faf2bccec1
2 changed files with 41 additions and 1 deletions

View File

@@ -379,7 +379,7 @@ Type ResultBuilderTypeRequest::evaluate(Evaluator &evaluator,
// Resolve a type for the attribute.
auto mutableAttr = const_cast<CustomAttr*>(attr);
auto dc = decl->getDeclContext();
auto *dc = decl->getInnermostDeclContext();
auto &ctx = dc->getASTContext();
Type type = evaluateOrDefault(
evaluator,

View File

@@ -0,0 +1,40 @@
// No warnings.
// RUN: %target-typecheck-verify-swift
//
// RUN: %target-run-simple-swift | %FileCheck %s
//
// REQUIRES: executable_test
@resultBuilder
struct Builder<T> {
static func buildBlock(_ args: T...) -> [T] { args }
}
// https://github.com/swiftlang/swift/issues/72739
do {
@Builder<T>
func buildArray<T>(_ t1: T, _ t2: T, _ t3: T) -> [T] {
t1
t2
t3
}
enum TypeContext {
@Builder<T>
static func buildArray<T>(_ t1: T, _ t2: T, _ t3: T) -> [T] {
t1
t2
t3
}
}
// CHECK: begin
print("begin")
// CHECK-NEXT: [1, 2, 3]
print(buildArray(1, 2, 3))
// CHECK-NEXT: [1, 2, 3]
print(TypeContext.buildArray(1, 2, 3))
// CHECK-NEXT: end
print("end")
}