swift: Passing a pointer in a ternary doesn't let you refer to local varible. "error: use of extraneous '&'"
func takesAPointer(_ y: UnsafeMutablePointer<OpaquePointer?>?) {
// ...
}
var x: OpaquePointer?
takesAPointer(&x) // works
takesAPointer(true ? (&x) : nil) // test.swift:9:22: error: use of extraneous '&'
Same error with or without the inner parens. This problem showed up when calling a C API that behaves differently in the presence of an out parameter.
swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) Target: x86_64-apple-macosx11.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (7 by maintainers)
Commits related to this issue
- [Diagnostics] Improve diagnostic message for extraneous `&` Resolves: https://github.com/apple/swift/issues/58389 — committed to xedin/swift by xedin 2 years ago
'&' may only be used to pass an argument to 'inout' parameter