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
In the Swift 5.3 and master branches, when you forward #file to a function that is defaulted to #filePath, you get the following warning:
/private/tmp/test_package_VdXUpS/Sources/Other/module.swift:7:20: warning: parameter 'file' with default argument '#file' passed to parameter 'file', whose default argument is '#filePath'
whatever(file: file)
^
/private/tmp/test_package_VdXUpS/Sources/Other/module.swift:6:46: note: did you mean for parameter 'file' to default to '#filePath'?
public func printMyFile(file: StaticString = #file) {
^~~~~
#filePath
/private/tmp/test_package_VdXUpS/Sources/Other/module.swift:7:20: note: add parentheses to silence this warning
whatever(file: file)
^
( )
/private/tmp/test_package_VdXUpS/Sources/Other/module.swift:10:15: note: 'file' declared here
func whatever(file: StaticString = #filePath) {
^
Using #filePath is only possible when using Swift 5.3 so not available to most Swift packages. Fortunately, the compiler offers
/private/tmp/test_package_VdXUpS/Sources/Other/module.swift:7:20: note: add parentheses to silence this warning
whatever(file: file)
^
( )
but doing so only works IFF applied to the call's parameter (and not in the function decl file: StaticString = (#file) which silences the warning too). That's super confusing and you'll end up getting the wrong file path. The worst is that this is primarily used in tests so the problem remains hidden until you get a test failure (which will then show up in the wrong file). See attached example project.
I can't really believe this but because of SR-12934 the absolutely necessary forwarding of #file to #filePath seems impossible (when writing the issue I believed that (#file) actually works).
Whilst implementing this change, despite it very clearly being backwards compatibility changing, the Swift project failed to up the -swift-version number (SR-12936). This is so very disappointing :'(.
This needs fixing ASAP before Swift 5.3 is out, either by fixing SR-12934 or SR-12936.
Repro:
import Other
print("The following two lines should read equally\n")
print("\(#file)")
printMyFile()
// MODULE: Other
public func printMyFile(file: StaticString = (#file)) {
whatever(file: file)
}
func whatever(file: StaticString = #filePath) {
print(file)
}
prints
The following two lines should read equally
/tmp/test_package_j8xPzy/Sources/TestApp/main.swift
/tmp/test_package_j8xPzy/Sources/Other/module.swift
The text was updated successfully, but these errors were encountered:
Attachment: Download
Additional Detail from JIRA
md5: ce9ac6b944a9a11dee601f23700669b9
Issue Description:
In the Swift 5.3 and master branches, when you forward
#file
to a function that is defaulted to#filePath
, you get the following warning:Using
#filePath
is only possible when using Swift 5.3 so not available to most Swift packages. Fortunately, the compiler offersbut doing so only works IFF applied to the call's parameter (and not in the function decl
file: StaticString = (#file)
which silences the warning too). That's super confusing and you'll end up getting the wrong file path. The worst is that this is primarily used in tests so the problem remains hidden until you get a test failure (which will then show up in the wrong file). See attached example project.I can't really believe this but because of SR-12934 the absolutely necessary forwarding of
#file
to#filePath
seems impossible (when writing the issue I believed that(#file)
actually works).Whilst implementing this change, despite it very clearly being backwards compatibility changing, the Swift project failed to up the
-swift-version
number (SR-12936). This is so very disappointing :'(.This needs fixing ASAP before Swift 5.3 is out, either by fixing SR-12934 or SR-12936.
Repro:
prints
The text was updated successfully, but these errors were encountered: