You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bug (in the example code, not in Swift) is that logDefault receives an Array<CVarArg> in its args parameter, and passes it to os_log, which is expecting variadic CVarArg arguments. Since Array conforms to CVarArg, Swift casts args to CVarArg implicitly.
The bug in Swift is that the conversion of Array<CVarArg> to CVarArg is rarely the desired behavior. (What's wanted is argument splatting, but I think that's unlikely to happen any time soon.) Swift should emit a warning when Array<CVarArg> is implicitly converted to CVarArg, and require an explicit cast to silence the warning.
Environment
macOS 10.13.5 (17F77)
Xcode Version 10.0 beta 2 (10L177m)
Toolchain: Swift 4.2 Snapshot 2018-06-19 (a)
Additional Detail from JIRA
md5: 3c00c89e0804ded75ece394b8719c377
relates to:
Issue Description:
Consider this:
This code compiles and runs without warning, but produces unexpected output:
The bug (in the example code, not in Swift) is that
logDefault
receives anArray<CVarArg>
in itsargs
parameter, and passes it toos_log
, which is expecting variadicCVarArg
arguments. SinceArray
conforms toCVarArg
, Swift castsargs
toCVarArg
implicitly.The bug in Swift is that the conversion of
Array<CVarArg>
toCVarArg
is rarely the desired behavior. (What's wanted is argument splatting, but I think that's unlikely to happen any time soon.) Swift should emit a warning whenArray<CVarArg>
is implicitly converted toCVarArg
, and require an explicit cast to silence the warning.P.S. This issue is based on https://stackoverflow.com/q/50937765/77567
The text was updated successfully, but these errors were encountered: