<div dir="ltr">This particular case doesn&#39;t quite relate to the URL literal/regex discussion, which would require a complex new static evaluation feature. For this, the compiler *already has* <a href="https://github.com/apple/swift/blob/master/lib/Sema/CSApply.cpp#L1893">logic</a> to determine whether a string literal is expressible as a UnicodeScalar, a Character, or a String; it&#39;s just applied differently when you write `Character(&quot;ax&quot;)` vs. `&quot;ax&quot; as Character`, presumably because of the way the type checker resolves the former to be calling the initializer that takes a String and thus only treats the literal as a String.<div><br></div><div>In fact, I recall that John McCall raised this exact issue a while back in the context of integers:</div><div><br></div><div>&quot;[swift-evolution] Proposal: &#39;T(literal)&#39; should construct T using the appropriate literal protocol if possible&quot;</div><div><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160530/019950.html">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160530/019950.html</a></div><div><br></div><div>Wherein the following expression that looks valid traps at runtime because it tries to convert the literal to an Int first (which is signed and therefore overflows) before calling the UInt64 initializer:</div><div><br></div><div>    let x = UInt64(0x8000_0000_0000_0000)</div><div><br></div><div>We&#39;ve gotten a bit off-topic from the original point of this thread, but this seems like an item that should be revisited soon, especially if it has ABI consequences. I wonder if John or another core team member can chime in.</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 11, 2017 at 9:53 PM David Sweeris &lt;<a href="mailto:davesweeris@mac.com">davesweeris@mac.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">On Jan 11, 2017, at 23:12, Tony Allevato &lt;<a href="mailto:tony.allevato@gmail.com" class="gmail_msg" target="_blank">tony.allevato@gmail.com</a>&gt; wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div dir="ltr" class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Jan 11, 2017 at 6:46 PM Jay Abbott via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="m_1961702581938037273m_2644463424369178424markdown-here-wrapper gmail_msg"><p style="margin:0px 0px 1.2em!important" class="gmail_msg">As Rob Mayoff pointed out, you can use MODIFIER LETTER PRIME - or PRIME, DOUBLE PRIME, and TRIPLE PRIME - which makes more sense than an apostrophe. Now if only there were a keyboard that had a touch-screen at the top which could be used for typing context-sensitive characters that would otherwise be difficult to type. So yeah, solution is to make characters easier to type, not modify the language. If like me you don&#39;t have such a keyboard, you can always use <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">ctrl</code>+<code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">⌘</code>+<code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">&lt;space&gt;</code> and type ‘PRIME’ to find it, then pick it from recently used/favourites.</p>
<p style="margin:0px 0px 1.2em!important" class="gmail_msg">Regarding the other point, I agree that character literals would be handy, but again I’m not sure if apostrophe is the right character to indicate it. Although it is familiar, perhaps LEFT SINGLE QUOTATION MARK and RIGHT SINGLE QUOTATION MARK would be better, they can be relatively easily typed with <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">⎇</code>+<code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">]</code> and <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">⎇</code>+<code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">⇧</code>+<code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">]</code> respectively. Xcode could also convert two apostrophes into ‘’ for you and your fingers would quickly learn to type <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">&#39;</code> <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">&#39;</code> <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">←</code> <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">‹char›</code>.</p></div></div></blockquote><div class="gmail_msg">I&#39;m not entirely convinced that we *need* special Character literals. The type checker is already able to treat a double-quoted string literal as a String, Character, or UnicodeScalar based on context in most places. Wouldn&#39;t it be more valuable to fill the gaps, like Charlie Monroe mentioned above, where these work:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">    let c: Character = &quot;a&quot;</div><div class="gmail_msg">    let c = &quot;a&quot; as Character</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">and this is caught as an error by the compiler:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">    let c: Character = &quot;ax&quot;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">but this slips through and crashes at runtime?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">    let c = Character(&quot;ax&quot;)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I wonder what improvements could be made in the compiler to have that last one do something more appropriate than just call Character.init(String), which causes the runtime error.</div></div></div>
</blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">This reminds me of the &quot;URL literal&quot; thread. I believe the two ideas were essentially to add regex support to the compiler, add support for compiler &quot;validation&quot; of literals through compile-time functions, or both.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">IIRC, it was decided that both ideas were at least out of scope for phase 1 (I don&#39;t recall if this specific issue was brought up as a potential use case, though... unlike `Character`, `URL` isn&#39;t part of the stdlib).</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">- Dave Sweeris</div></div></blockquote></div>