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
This type can either represent an array of strings or a string and it should be possible to initialize it with either an array literal (of strings) or a string literal. I want to use those initializers implicitly by declaring an array of Foo like that:
letfoos:[Foo]=[[],["a"],"a",]
Having the [Foo] array only contain array literals works fine, only strings works fine as well but having both requires me to add `as Foo` to either all strings or all arrays. It seems that there's a bug in the evaluation of the literal's type which doesn't take the declaration context into consideration.
The text was updated successfully, but these errors were encountered:
Hmm, feels like a bug as the inferred type depends on which element comes first. In the meantime, here's a possible workaround:
enumFoo:ExpressibleByArrayLiteral,ExpressibleByStringLiteral{case arr([String])case str(String)init(stringLiteral value:String){self=.str(value)}init(arrayLiteral elements:Foo...){self=.arr(elements.compactMap{
if case let.str(value)= $0 {return value
}returnnil})}}letfoos:[Foo]=[[],["a"],"a"]
Environment
This happens in a recent Swift compiler but is probably not limited to that version.
Additional Detail from JIRA
md5: 751621a4d7f44f5a92aa26c4559a03c2
Issue Description:
I have code similar to the following snippet:
This type can either represent an array of strings or a string and it should be possible to initialize it with either an array literal (of strings) or a string literal. I want to use those initializers implicitly by declaring an array of Foo like that:
Having the [Foo] array only contain array literals works fine, only strings works fine as well but having both requires me to add `as Foo` to either all strings or all arrays. It seems that there's a bug in the evaluation of the literal's type which doesn't take the declaration context into consideration.
The text was updated successfully, but these errors were encountered: