[swift-evolution] Implicit truncation
xiaodi.wu at gmail.com
Mon May 22 07:18:31 CDT 2017
There are no non-failable value-preserving conversions from floating point
values of any type to integers of any type. The API naming guidelines do
not require that _only_ value-preserving type conversions omit the first
argument; in this case, a strong convention among C family languages exists
for the behavior of the conversion, and the guidelines tell us to omit
needless words. This spelling has already been reviewed and approved for
Swift 4. What are the "subtle bugs all over the place" that you observe,
and what did those users expect to happen?
On Mon, May 22, 2017 at 06:17 Rudolf Adamkovič via swift-evolution <
swift-evolution at swift.org> wrote:
> Reply below.
> On 22 May 2017, at 06:44, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org> wrote:
> […], but the unlabeled spelling is not harmful, as `Int.init(_: Float)` is
> after all a non-failable initializer that converts from a floating point
> value to an integer value.
> I respectfully disagree. From my experience (tutoring), this is harmful.
> It leads to subtle bugs all over the place. That’s what I observe.
> Another citation from Swift API Guidelines:
> In initializers that perform value preserving type conversions, omit the
> first argument label, e.g. Int64(someUInt32)
> This is not a value preserving conversion, is it?
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution