<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">In Swift 3, I can declare a postfix operator that starts with a ? or a !, but as far as I can tell, there's no way to actually use such an operator:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix operator ?**</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix func ?**(x: Int) -&gt; Int { return x }</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let x = 12</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">x?**<span class="Apple-tab-span" style="white-space:pre">                        </span>//&nbsp;error: use of unresolved operator '**'</font></div></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix operator !**</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix func !**(x: Int) -&gt; Int { return x }</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let x = 12</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">x!**<span class="Apple-tab-span" style="white-space:pre">                        </span>// error: use of unresolved operator '**'</font></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">It makes sense to me, why that happens. There's no way for the parser to know, whether ?** is the end of an optional chaining expression</div><div style="margin: 0px; line-height: normal;" class="">followed by a postfix operator ** or whether it's a single postfix operator ?**. Similarly, !** could refer to a forced-value expression followed</div><div style="margin: 0px; line-height: normal;" class="">by a postfix operator ** or a single postfix operator !**.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Even with semantic knowledge, it is unclear, what should happen. For example, in the following situation either parsing decisions would</div><div style="margin: 0px; line-height: normal;" class="">result in a valid program:</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix operator ++</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix operator ?++</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix func ++(x: inout Int) {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">&nbsp; &nbsp; x += 1</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">postfix func ?++(x: Int?) -&gt; Int? {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">&nbsp; &nbsp; return x</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">var x: Int? = 0</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">x?++<span class="Apple-tab-span" style="white-space:pre">                </span>// what should happen here? Swift 3 chooses optional chaining expression followed by ++ operator</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class="">I think it would probably be best to disallow postfix operators that start with a question mark or an exclamation mark.</div><div style="margin: 0px; line-height: normal;" class="">At the moment it is possible to declare them, but not to use them. That's not very user-friendly.&nbsp;</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">By the way, infix operators have a similar problem. Infix operators that start with a ? or a ! must be surrounded by whitespace whereas</div><div style="margin: 0px; line-height: normal;" class="">other infix operators don't have to be:</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let x: Int? = 0</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">x ?? 10 <span class="Apple-tab-span" style="white-space:pre">        </span>// fine</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">x??0 <span class="Apple-tab-span" style="white-space:pre">                </span>// error</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">2 + 10<span class="Apple-tab-span" style="white-space:pre">                </span>// fine</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">2+10<span class="Apple-tab-span" style="white-space:pre">                </span>// fine</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class="">I think this is less of an issue, because you can at least use such infix operators if you add the necessary whitespace.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">What do you think about this? Would it make sense to disallow postfix operators that start with a question mark or an exclamation mark?</div></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Thanks and best regards,</div><div style="margin: 0px; line-height: normal;" class="">Toni</div></div></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>