> On Jun 2, 2016, at 9:08 AM, John McCall via swift-evolution > <[email protected]> wrote: > > The official way to build a literal of a specific type is to write the > literal in an explicitly-typed context, like so: > let x: UInt16 = 7 > or > let x = 7 as UInt16 > > Nonetheless, programmers often try the following: > UInt16(7) > > Unfortunately, this does not attempt to construct the value using the > appropriate literal protocol; it instead performs overload resolution using > the standard rules, i.e. considering only single-argument unlabelled > initializers of a type which conforms to IntegerLiteralConvertible. Often > this leads to static ambiguities or, worse, causes the literal to be built > using a default type (such as Int); this may have semantically very different > results which are only caught at runtime.
+1 to the proposal; I’m embarrassed to admit I thought it worked this way already. Any type that wants more control shouldn’t be adopting the literal convertible protocols anyway. Russ
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
