-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single Quoted Literals. #61477
Single Quoted Literals. #61477
Conversation
|
Hey @johnno1962, this is good work. Before I review it, is there a corresponding re-pitch on the forums? |
|
Hi @CodaFi, thanks for noticing the PR. I'm a little back-to-front when I attempt to evolve Swift: I start with an exploratory implementation to see what is possible, write the proposal then pitch it 🙃. At the moment I'm looking through the last epic review thread to see how much further along we are. Adding the two new ExpressibleBy protocols helps differentiate the two forms and the integer convertibility is more focused and won't even compile if the literal isn't ASCII but |
|
Some progress on a a draft proposal: https://github.com/johnno1962/swift-evolution/pull/4/files. Should be enough to form an opinion on the PR; There isn't much to it. It offers nearly the same functionality as the previously rejected implementation without the cost of some source breaks that were identified. |
|
I'm closing this now as there doesn't seem to be much appetite for a proposal that would drag Swift back into the 20th century when characters were convertible to integer values. Sad. |
Hi Apple,
As the last potential holdouts for using the single quote character in Swift (raw strings & perhaps regexes) have been adjudicated, perhaps it is time for a new implementation + pitch for "Character literals" using a single quoted
'c'syntax. This new implementation is additive rather than source breaking as was the previously proposed implementation apple/swift#21873 adding the single quoted syntax as a synonym for double quoted syntax specifically forCharacterandUnicodeScalarliterals, the difference being they have a default type ofCharacter(configurable) instead ofString.In addition, single quoted
ASCIIcharacter literals can express/initialise integers for use in "old school" code point arithmetic as was proposed previously but without requiring a source breaking change at some point in the future. Many issues discussed in the last review have been addressed by implementing better differentiation between double and single quoted literals using the two new marker protocolsExpressibleBySingleQuotedLiteralandExpressibleByASCIILiteralwhich are refined by the existing string literal protocols. This should not affect their ABI as the new protocols use the@_markerattribute.Consult the test/Parse/single_quoted_literal.swift file in the diff for a sample of new capabilities.
I'd be very interested in the results of a run of the "Source compatibility Suite" if someone would be kind enough to run one as this is intended to be a non-source breaking addition by using the single quote character which not currently valid Swift syntax. The changes are relatively minor overall.
A toolchain is available for evaluation on google drive
Resolves #51535, originally SR-9032 .