<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 17, 2015, at 4:33 PM, David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><br class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">What other solutions can we think up? We already discussed using other prefix keywords which are less verbose than self, but couldn't come up with any great solution. I would just like the language help us here to make things safer without everybody using their own naming conventions or Hungarian notation.</div></div></blockquote><br class=""></div><div>I believe that the compiler should give warnings (on use, not declaration/import) of a variable or function overload which has been implicitly shadowed and is ambiguous. Explicit shadowing today I believe is only defined by<b class=""><i class=""> let x=x</i></b> or<b class=""><i class=""> var x=x</i></b> (where the local copy and original have the same name). Of course, a recommendation for resolving these issues would be part of any such proposal.</div><div><br class=""></div><div>That does still leave the following issue from your proposal:</div><div><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; color: rgb(51, 51, 51);" class=""> <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);">updateButton</span>() {
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// var title = "Hello \(name)"</span>
button<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>setTitle(title, forState: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Normal) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// forgot to comment this line but the compiler does not complain and title is now referencing UIViewController’s title by mistake</span>
button<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>setTitleColor(UIColor<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>blackColor(), forState: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Normal)
}</pre><div class=""><br class=""></div></div><div>This is not ambiguous, so I would not expect such a problem to take long to debug. Moreso, any run of the code *before* they commented out the var title=… line would have had a warning about the shadowing.</div><div><br class=""></div><div>This would also make some of the method cascading approaches (where a value behave like an implicit self within a block of code) possible without introducing massive ambiguity - the compiler likely just requires you to fully specify the types in the case where your names are ambiguous. Who knows, this might encourage people to come up with more descriptive names! ;-) </div><div> </div><div>-DW</div></body></html>