diff --git a/lib/Sema/TypeCheckRequestFunctions.cpp b/lib/Sema/TypeCheckRequestFunctions.cpp index ecf965e0ed8..01929c1893f 100644 --- a/lib/Sema/TypeCheckRequestFunctions.cpp +++ b/lib/Sema/TypeCheckRequestFunctions.cpp @@ -379,7 +379,7 @@ Type ResultBuilderTypeRequest::evaluate(Evaluator &evaluator, // Resolve a type for the attribute. auto mutableAttr = const_cast(attr); - auto dc = decl->getDeclContext(); + auto *dc = decl->getInnermostDeclContext(); auto &ctx = dc->getASTContext(); Type type = evaluateOrDefault( evaluator, diff --git a/test/Constraints/result_builder_generic_exec.swift b/test/Constraints/result_builder_generic_exec.swift new file mode 100644 index 00000000000..f00e08bd482 --- /dev/null +++ b/test/Constraints/result_builder_generic_exec.swift @@ -0,0 +1,40 @@ +// No warnings. +// RUN: %target-typecheck-verify-swift +// +// RUN: %target-run-simple-swift | %FileCheck %s +// +// REQUIRES: executable_test + +@resultBuilder +struct Builder { + static func buildBlock(_ args: T...) -> [T] { args } +} + +// https://github.com/swiftlang/swift/issues/72739 +do { + @Builder + func buildArray(_ t1: T, _ t2: T, _ t3: T) -> [T] { + t1 + t2 + t3 + } + + enum TypeContext { + @Builder + static func buildArray(_ 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") +} +