Skip to content

Commit 995916a

Browse files
authored
Merge pull request #81051 from xedin/rdar-rdar-148168219-6.2
[6.2][Sema] ConstnessChecker: Look through function conversions while chec…
2 parents cbcaf5e + be01690 commit 995916a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/Sema/ConstantnessSemaDiagnostics.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ static Expr *checkConstantness(Expr *expr) {
175175
return expr;
176176

177177
ApplyExpr *apply = cast<ApplyExpr>(expr);
178-
ValueDecl *calledValue = apply->getCalledValue();
178+
ValueDecl *calledValue =
179+
apply->getCalledValue(/*skipFunctionConversions=*/true);
179180
if (!calledValue)
180181
return expr;
181182

@@ -300,7 +301,8 @@ static void diagnoseConstantArgumentRequirementOfCall(const CallExpr *callExpr,
300301
const ASTContext &ctx) {
301302
assert(callExpr && callExpr->getType() &&
302303
"callExpr should have a valid type");
303-
ValueDecl *calledDecl = callExpr->getCalledValue();
304+
ValueDecl *calledDecl =
305+
callExpr->getCalledValue(/*skipFunctionConversions=*/true);
304306
if (!calledDecl || !isa<AbstractFunctionDecl>(calledDecl))
305307
return;
306308
AbstractFunctionDecl *callee = cast<AbstractFunctionDecl>(calledDecl);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
3+
// REQUIRES: VENDOR=apple
4+
// REQUIRES: concurrency
5+
6+
import OSLogTestHelper
7+
8+
class Log {
9+
@_semantics("oslog.requires_constant_arguments")
10+
func debug(_: OSLogMessage) {}
11+
}
12+
13+
@_semantics("constant_evaluable")
14+
@_transparent
15+
public func __outputFormatter(_ key: String, fallback: OSLogMessage) -> OSLogMessage {
16+
fallback
17+
}
18+
19+
@MainActor
20+
@_semantics("constant_evaluable")
21+
@_transparent
22+
public func __isolatedOutputFormatter(_ key: String, fallback: OSLogMessage) -> OSLogMessage {
23+
fallback
24+
}
25+
26+
func test(log: Log) {
27+
log.debug(__outputFormatter("1", fallback: "msg")) // Ok
28+
}
29+
30+
@MainActor
31+
func isolatedTest(log: Log) {
32+
log.debug(__isolatedOutputFormatter("1", fallback: "msg")) // Ok
33+
}

0 commit comments

Comments
 (0)