diff --git a/lib/Sema/LegalConstExprVerifier.cpp b/lib/Sema/LegalConstExprVerifier.cpp index 62f3c611def0c..6381ba33dbb86 100644 --- a/lib/Sema/LegalConstExprVerifier.cpp +++ b/lib/Sema/LegalConstExprVerifier.cpp @@ -241,7 +241,8 @@ checkSupportedWithSectionAttribute(const Expr *expr, functionConvExpr->getType()->getAs()) { if (targetFnTy->getExtInfo().getRepresentation() == FunctionTypeRepresentation::CFunctionPointer) { - expressionsToCheck.push_back(functionConvExpr->getSubExpr()); + // Do not check the inner expression -- if it converts to + // CFunctionPointer successfully, then it's constant foldable. continue; } } diff --git a/test/ConstValues/SectionSyntactic.swift b/test/ConstValues/SectionSyntactic.swift index ce2165a25cc36..87d6d5b9897a8 100644 --- a/test/ConstValues/SectionSyntactic.swift +++ b/test/ConstValues/SectionSyntactic.swift @@ -93,6 +93,14 @@ extension Q { @section("mysection") static let invalidFuncRef8: (Int)->() = stat struct W { @section("mysection") static let closure7: @convention(c) (Int) -> Int = { x in x * 2 } // ok } +func g() { + @Sendable func f() { } + @Sendable func h() async { } + enum E { + @section("mysection") static let record: @convention(c) () -> () = { f() } // ok + @section("mysection") static let record2: @convention(c) () -> () = { _ = h } // ok + } +} let capturedVar = 10 class TestClass {}