SE-0243: Codepoint and Character Literals

Revew Conclusion

The review for SE-0243 has ended and the proposal has been rejected.

To move forward on this topic, and to help the community converge on more of a consensus around these features, the core team recommends breaking this proposal out into two separate proposals that could be re-pitched and (depending on the pitch outcome) re-run.

Introducing a single-quoted literal

The core team supports the direction of adding single quotes for character and scalar literals to the language, and this has broad support from the community. This part of the proposal should become a new stand-alone proposal.

This part of the proposal is also not affected by the ABI stability issues relating to backward deployment of conformances.

There was some discussion during the review of whether the "default" for these should be the Character or Unicode.Scalar type, and the pros and cons for choosing one over the other should be discussed in the pitch phase.

String and character literals

One concern raised during the review was that because ExpressibleByStringLiteral refines ExpressibleByExtendedGraphemeClusterLiteral, then type context will allow expressions like 'x' + 'y' == "xy". The core team agrees that this is unfortunate and that if these protocols were redesigned, this refinement would not exist. However, this is not considered enough of an issue to justify introducing new protocols to avoid the problem. Where practical, the implementation of single-quote literals should generate compile-time warnings for these kind of misuses – though this should not be done by adding additional deprecated operators to the standard library.

In the longer term, the core team thinks that the overall mechanism for literals in Swift should be re-evaluated. This re-evaluation could also cover other features, such as a mechanism for arbitrary-precision numeric literals. This is a large undertaking, however, and should not hold up a proposal for single-quoted literals.

Expressing integer types with character literals

This was the cause of the majority of disagreement during the review. Once single-quoted literals have been added to the language, this part of the proposal (or an alternative, such as the addition of a trapping or nil-returning ascii property) can be re-pitched separately.

Thanks for all your contributions during this review!

Ben Cohen
Review Manager

21 Likes