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
SR-10259ExpressibleByStringLiteral masks an initializer without any warning in Swift 5.
Issue Description:
I've got this type conformed to ExpressibleByStringLiteral, but I don't want that initializer to be invoked if I initialize the type directly via Example("foo"). (In the real code this came from, I want to capture #file and #line at the initialization site, and that's not happening because the wrong initializer is being selected.)
structExample {
letvalue: Stringinit(_value: String) {
print(#function) // this does not printself.value = value
}
}
extensionExample: ExpressibleByStringLiteral {
init(stringLiteralvalue: String) {
print(#function) // this printsself.value = value
}
}
letx = Example("foo")
The text was updated successfully, but these errors were encountered:
Thanks to @sharplet for pointing out that this is expected behavior, and is a result of SE-0213. Adam shared a couple of workarounds, including Example.init("foo") and Example("foo" as String). Posting them here in case they help someone else who is surprised by this behavior. In my case, I'm only using the protocol as a band-aid to help me get through a big refactor, so I'll be removing it before merging anyway.
Environment
Xcode 11.3 (11C29) on macOS 10.15.2 (19C57)
Additional Detail from JIRA
md5: e59adf842cff91a91c3807f16c38aeda
duplicates:
ExpressibleByStringLiteral
masks an initializer without any warning in Swift 5.Issue Description:
I've got this type conformed to
ExpressibleByStringLiteral
, but I don't want that initializer to be invoked if I initialize the type directly viaExample("foo")
. (In the real code this came from, I want to capture#file
and#line
at the initialization site, and that's not happening because the wrong initializer is being selected.)The text was updated successfully, but these errors were encountered: