Working on a function for Foundation’s Scanner I stumbled on this LLVM crash: [SR-3295] LLVM Crash using AutoreleasingUnsafeMutablePointer<Bool?>? · Issue #45883 · apple/swift · GitHub
This got me thinking about a workaround and I would like to prose this:
When importing Foundation into Swift 3, all
AutoreleasingUnsafeMutablePointer<T?>?
should instead be exposed as simple:
inout T?
e.g.
open func scanString(_ string: String, into result: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool
would become
open func scanString(_ string: String, into result: inout String?) -> Bool
The call would stay exactly the same for normal use cases where you specify a receiving variable:
var string: String?
scanString("=", into: &string)
because inout parameters require a &
for the use case where you don’t require a receiving parameter, a second method without result parameter would be generated:
open func scanString(_ string: String) -> Bool
This is necessary because you cannot specify nil or an immutable value for an inout parameter.
A fixit/migration would change calls to
scanString(“foo", into result: nil)
into
scanString(“foo")
The normal call with receiving variable would stay the same. But the case without return would become more concise.
What do you think?
kind regards
Oliver Drobnik