[swift-evolution] Auto-convert for numbers when safe

William Shipley wjs at mac.com
Sun Dec 6 20:35:32 CST 2015


I’m new to this discussion and don’t really know what’s been tried before, so I’m probably asking stupid questions, but I *really* want auto-conversion…

What would be the drawback in terms of language design to just allowing types to specify what other types can automatically be “upconverted" to them? True, this could be used to create a cyclic graph, but that could just be disallowed in the compiler—you guys like writing code, right?

I think one of the issues with all this is that Swift allows us to skip specifying types, like:

   let a = 1

   let b: CGFloat = a + 3

And so it’d be easy to get into a morass where the poor compiler is all, “AH! I should go back in time and make ‘a’ a CGFloat automatically, not an Int like I want, so it’ll add with 3 and make a nice CGFloat!”

Is that the problem we’re fighting? If not, what was the issue with the (unreleased) auto-conversion code that was in Swift.

-Wil


More information about the swift-evolution mailing list