<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I like this, but I think it needs to handle more cases to truly promote consistency.<div class=""><div class=""><br class=""></div><div class="">In static contexts, use of the case is consistent with that of a static variable or function (value directly in scope, so no dot prefix shortcut necessary).</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Booly {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> truth</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> falsehood</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> yes = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">truth</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> no = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">falsehood</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> defaulted() -> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(83, 154, 164);" class="">Booly</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">truth</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> workingAlternative() -> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(83, 154, 164);" class="">Booly</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> yes</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="">It is however a special case in the non-static context:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Booly {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> isDefault() -> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 34, 117);" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(41, 76, 80);" class="">==</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">truth</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> brokenYesVersion() -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// return self == yes // Error: Static member 'yes' cannot be used on instance of type 'Booly'</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #294c50" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .yes</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">And case usage is inconsistent in the body of a switch statement. In situations like an OptionSetType implementation, the compiler will complain about use of dot syntax w.r.t. not being an enumeration member. </span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Foundation</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> flags:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFStringCompareFlags</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = [.CompareAnchored]</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">flags</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// case .CompareAnchored: // Error: Enum case 'CompareAnchored' ont found in type 'CFStringCompareFlags'</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">CFStringCompareFlags</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.CompareAnchored:</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(201, 27, 19);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"Anchored"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ()</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">In the case of enumerations, it will complain about anything from the enumerated type other than the case label!</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> b:</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">Booly</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .yes</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// switch b {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// case yes: // Error: Use of unresolved identifier ‘yes’</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// case .yes: // Error: Enum case 'yes' not found in type 'Booly'</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// case Booly.yes: // Error: Enum case 'yes' not found in type 'Booly'</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">//}</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> externalYes = </span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">Booly</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">truth</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">b</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(83, 154, 164);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">externalYes</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(201, 27, 19);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures" class="">"finally, yes!"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ()</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></span></div><div class=""><br class=""></div><div class="">IMHO, the *only* thing that the compiler should do special with case variable usage is that, when the type beings switched over is an enum and the cases of that enum are all specified as possible cases of the switch, not require the use of a default section.</div><div class=""><br class=""></div><div class="">(playground code copied to <a href="https://gist.github.com/dwaite/60c8dc05e498b747d0f2" class="">https://gist.github.com/dwaite/60c8dc05e498b747d0f2</a> )</div><div class=""><br class=""></div><div class="">-DW</div></div><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 12, 2016, at 7:23 AM, Daniel Steinberg via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+1 for consistency reasons<div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 11, 2016, at 10:00 PM, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><a href="https://gist.github.com/erica/e0b8a3a22ab716a19db4" class="">https://gist.github.com/erica/e0b8a3a22ab716a19db4</a><div class=""><br class=""></div><div class=""><h1 style="box-sizing: border-box; font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">Requiring Leading Dot Prefixes for Enum Instance Member Implementations</h1><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">Proposal: TBD</li><li style="box-sizing: border-box;" class="">Author(s): <a href="http://github.com/erica" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">Erica Sadun</a>, <a href="https://github.com/lattner" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">Chris Lattner</a></li><li style="box-sizing: border-box;" class="">Status: TBD</li><li style="box-sizing: border-box;" class="">Review manager: TBD</li></ul><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-introduction" class="anchor" href="https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Introduction</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Enumeration cases are essentially static not instance type members. Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type. This makes little sense. In no other case can an instance implementation directly access a static member. This proposal introduces a rule that requires leading dots or fully qualified references (EnumType.caseMember) to provide a more consistent developer experience to clearly disambiguate static cases from instance members. </p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-motivation" class="anchor" href="https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Motivation</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Swift infers the enclosing type for a case on a developer's behalf when the use is unambiguously of a single enumeration type. Inference enables you to craft switch statements like this:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">switch</span> Coin() {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Heads: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Heads<span class="pl-pds" style="box-sizing: border-box;">"</span></span>)
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Tails: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Tails<span class="pl-pds" style="box-sizing: border-box;">"</span></span>)
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">A leading dot has become a conventional shorthand for "enumeration case" across the language. When used internally in <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">enum</code> implementations, a leading dot is not required, nor is a type name to access the static case member. The following code is legal in Swift.</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">enum</span> Coin {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> Heads, Tails
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">printMe</span>() {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">switch</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> Heads: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Heads<span class="pl-pds" style="box-sizing: border-box;">"</span></span>) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// no leading dot</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Tails: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Tails<span class="pl-pds" style="box-sizing: border-box;">"</span></span>) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// leading dot</span>
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">if</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">==</span> Heads { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// no leading dot</span>
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>This is a head<span class="pl-pds" style="box-sizing: border-box;">"</span></span>)
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">if</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">==</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Tails { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// leading dot</span>
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>This is a tail<span class="pl-pds" style="box-sizing: border-box;">"</span></span>)
}
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>() {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> cointoss <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> arc4random_uniform(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">2</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">==</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">0</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> cointoss <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">?</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Heads <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> Tails <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// mix and match leading dots</span>
}
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">This quirk produces a language inconsistency that can confuse developers and contravenes the guiding <em style="box-sizing: border-box;" class="">Principle of Least Astonishment</em>. We propose to mandate a leading dot. This will bring case mentions into lock-step with the conventions used to reference them outside of enumeration type implementations.</p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-detail-design" class="anchor" href="https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Detail Design</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Under this rule, the compiler will require a leading dot for all case members. The change will not affect other static members, which require fully qualified references from instance methods and infer <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">self</code> from static methods.</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">enum</span> Coin {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> Heads, Tails
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">doSomething</span>() { <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Something<span class="pl-pds" style="box-sizing: border-box;">"</span></span>) }
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">staticFunc</span>() { doSomething() } <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// does not require leading dot</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">staticFunc2</span>() { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> foo <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Tails } <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// requires leading dot</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">instanceFunc</span>() { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">dynamicType</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>doSomething() } <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// requires full qualification</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">otherFunc</span>() { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">if</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">==</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Heads <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">...</span> } <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// requires leading dot, also initializers</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ...</span>
} </pre></div><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-alternatives-considered" class="anchor" href="https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Alternatives Considered</h2><div style="box-sizing: border-box; margin-top: 0px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255); margin-bottom: 0px !important;" class="">Other than leaving the status quo, the language could force instance members to refer to cases using a fully qualified type, as with other static members.</div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>