-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
@autoclosureFeature → attributes: the @autoclosure type attributeFeature → attributes: the @autoclosure type attributebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.ownershipFeature: Ownership modifiers and semanticsFeature: Ownership modifiers and semantics
Description
Description
A function's borrowed parameter cannot be used in a precondition's autoclosure. The error claims that the parameter "cannot be captured by an escaping closure since it is a borrowed parameter". It's not clear why an autoclosure should be considered escaping. Note that this error occurs after type checking.
Reproduction
public func test(_ i: borrowing Int) -> Bool {
precondition(i > 0)
return true
}
Expected behavior
This should compile.
However,
<source>:1:20: error: 'i' cannot be captured by an escaping closure since it is a borrowed parameter
1 | public func test(_ i: borrowing Int) -> Bool {
| `- error: 'i' cannot be captured by an escaping closure since it is a borrowed parameter
2 | precondition(i > 0)
| `- note: closure capturing 'i' here
3 | return true
4 | }
https://swift.godbolt.org/z/v4d3YWrPv
Environment
Apple Swift version 6.1-dev (LLVM f4b733c38006ec1, Swift f4bea5f)
Target: arm64-apple-macosx15.0
(https://github.com/swiftlang/swift/releases/tag/swift-DEVELOPMENT-SNAPSHOT-2024-10-27-a)
Additional information
rdar://138670128
Metadata
Metadata
Assignees
Labels
@autoclosureFeature → attributes: the @autoclosure type attributeFeature → attributes: the @autoclosure type attributebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.ownershipFeature: Ownership modifiers and semanticsFeature: Ownership modifiers and semantics