Skip to content

Commit 2d6ed72

Browse files
committed
SE-0492: Allow any @convention(c) function conversions
1 parent 15cb8d6 commit 2d6ed72

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Sema/LegalConstExprVerifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ checkSupportedWithSectionAttribute(const Expr *expr,
241241
functionConvExpr->getType()->getAs<AnyFunctionType>()) {
242242
if (targetFnTy->getExtInfo().getRepresentation() ==
243243
FunctionTypeRepresentation::CFunctionPointer) {
244-
expressionsToCheck.push_back(functionConvExpr->getSubExpr());
244+
// Do not check the inner expression -- if it converts to
245+
// CFunctionPointer successfully, then it's constant foldable.
245246
continue;
246247
}
247248
}

test/ConstValues/SectionSyntactic.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ extension Q { @section("mysection") static let invalidFuncRef8: (Int)->() = stat
9393
struct W {
9494
@section("mysection") static let closure7: @convention(c) (Int) -> Int = { x in x * 2 } // ok
9595
}
96+
func g() {
97+
@Sendable func f() { }
98+
@Sendable func h() async { }
99+
enum E {
100+
@section("mysection") static let record: @convention(c) () -> () = { f() } // ok
101+
@section("mysection") static let record2: @convention(c) () -> () = { _ = h } // ok
102+
}
103+
}
96104

97105
let capturedVar = 10
98106
class TestClass {}

0 commit comments

Comments
 (0)