Skip to content

Commit 4045951

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

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ 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+
enum E {
99+
@section("mysection") static let record: @convention(c) () -> () = { f() } // ok
100+
}
101+
}
96102

97103
let capturedVar = 10
98104
class TestClass {}

0 commit comments

Comments
 (0)