mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] ConstnessChecker: Look through function conversions while checking arguments
In strict concurrency mode some calls could reference a declaration that is wrapped in one or more function conversion expressions to apply concurrency related attributes or erase them (such as `@Sendable` or `@MainActor`). This shouldn't impact constness checking and the checker should look through such conversions. Resolves: rdar://148168219
This commit is contained in:
@@ -175,7 +175,8 @@ static Expr *checkConstantness(Expr *expr) {
|
||||
return expr;
|
||||
|
||||
ApplyExpr *apply = cast<ApplyExpr>(expr);
|
||||
ValueDecl *calledValue = apply->getCalledValue();
|
||||
ValueDecl *calledValue =
|
||||
apply->getCalledValue(/*skipFunctionConversions=*/true);
|
||||
if (!calledValue)
|
||||
return expr;
|
||||
|
||||
@@ -300,7 +301,8 @@ static void diagnoseConstantArgumentRequirementOfCall(const CallExpr *callExpr,
|
||||
const ASTContext &ctx) {
|
||||
assert(callExpr && callExpr->getType() &&
|
||||
"callExpr should have a valid type");
|
||||
ValueDecl *calledDecl = callExpr->getCalledValue();
|
||||
ValueDecl *calledDecl =
|
||||
callExpr->getCalledValue(/*skipFunctionConversions=*/true);
|
||||
if (!calledDecl || !isa<AbstractFunctionDecl>(calledDecl))
|
||||
return;
|
||||
AbstractFunctionDecl *callee = cast<AbstractFunctionDecl>(calledDecl);
|
||||
|
||||
33
test/Sema/diag_constantness_check_os_log_swift6.swift
Normal file
33
test/Sema/diag_constantness_check_os_log_swift6.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 6
|
||||
|
||||
// REQUIRES: VENDOR=apple
|
||||
// REQUIRES: concurrency
|
||||
|
||||
import OSLogTestHelper
|
||||
|
||||
class Log {
|
||||
@_semantics("oslog.requires_constant_arguments")
|
||||
func debug(_: OSLogMessage) {}
|
||||
}
|
||||
|
||||
@_semantics("constant_evaluable")
|
||||
@_transparent
|
||||
public func __outputFormatter(_ key: String, fallback: OSLogMessage) -> OSLogMessage {
|
||||
fallback
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@_semantics("constant_evaluable")
|
||||
@_transparent
|
||||
public func __isolatedOutputFormatter(_ key: String, fallback: OSLogMessage) -> OSLogMessage {
|
||||
fallback
|
||||
}
|
||||
|
||||
func test(log: Log) {
|
||||
log.debug(__outputFormatter("1", fallback: "msg")) // Ok
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func isolatedTest(log: Log) {
|
||||
log.debug(__isolatedOutputFormatter("1", fallback: "msg")) // Ok
|
||||
}
|
||||
Reference in New Issue
Block a user