[swift-evolution] Potential problamatic initializers, solved by removing tuple splat?

Dany St-Amant dsa.mls at icloud.com
Sun Feb 7 10:47:31 CST 2016


> Le 7 févr. 2016 à 08:45, Jens Persson via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> let tenXs = String(count: 10, repeatedValue: Character("X"))
> let tenYs = String(count: 10, repaetedValue: Character("Y"))
> print(tenXs) // Prints XXXXXXXXXX
> print(tenYs) // Prints (10, "Y")
> 
> So, why doesn't tenYs print the expected YYYYYYYYYY?
> - Because of the slightly misspelled repeatedValues parameter label.
> 
> Then why no compile time error for the misspelled parameter label?
> - Because of this String intializer: public init<T>(_ instance: T)
> 
> I guess there are other similar examples, but I happened to stumble upon this one just now.
> 
> Should they be considered a problem?
> 
> Is this an example of a problem that will be solved by removing tuple splat?

Looks like some kind implicit tuple "unsplating", the reverse of what is mentioned in SE-0029: Removing implicit tuple splat

class sample
{
    init<T>(_ instance: T)
    {
        print(instance)
    }
}

let tenYs = sample(count: 10, repaetedValue: Character("Y"))

does display the same (10, "Y").

Dany


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160207/a33c1f2f/attachment.html>


More information about the swift-evolution mailing list