Literal initialization via coercion

Thanks for bringing this up! This is one of those parts of Swift that I've wanted to see cleaned up for a while.

It may be a good idea to read up on John McCall's thread from a couple years ago where he brought up the same issue, just to see if there's any valuable discussion about design/implementation. It's a shame this didn't get fixed back then.

You mention the case of UInt64(0xffff_ffff_ffff_ffff) becoming valid, as it should. But I would also mention that this turns some expressions that are currently only runtime errors into compiler errors (as they also should be, if the conversion is invalid). For example, "ab" as Character is currently a compile-time error but Character("ab") compiles and traps at runtime. Having the latter caught at compile time falls nicely out of this change.

5 Likes