<div dir="ltr">Hi all,<br><br>I'm fixing <font face="monospace, monospace">#if</font> condition processing in this PR<br><div><a href="https://github.com/apple/swift/pull/7955">https://github.com/apple/swift/pull/7955</a><br><br>It resolves these issues:</div><div><br><div><b>A) <a href="https://bugs.swift.org/browse/SR-3663">SR-3663</a>: Precedence of '&&' and '||' and short-circuit rule of them.<br></b><br><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">false</span> || true && false<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"> print("true")</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span>#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span></pre><div><br></div><div>This used to evaluate to '<font face="monospace, monospace">true</font>'.</div><div><br></div><b>B) <a href="https://bugs.swift.org/browse/SR-4032">SR-4032</a>: Version check with binary operator.<br></b><br><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">swift</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">>=</span><span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5.0</span>) <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&&</span> FOO
Some Swift <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5</span> code here
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span></pre><div><br></div><div>I believe, this block should not be parsed.</div><div><br></div><b>C) <a href="https://bugs.swift.org/browse/SR-3663">SR-3663</a>: Invalid condition after short-circuit binary operator.<br></b><br><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">true</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">||</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">true</span> * This is not <acceptable>!
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span></pre><div><br></div><div>This used to be accepted.</div><div><br></div><b>D) <a href="https://bugs.swift.org/browse/SR-4031">SR-4031</a>: Compound name in the condition<br></b><br><div><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> FOO(_:)
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">elseif</span> os(foo:)(macOS)
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">elseif</span> os(Linux(foo:bar:))
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span></pre><br></div></div></div><div>This used to be accepted.</div><div><br></div><div>In the PR, I keep A) and B) behavior in <font face="monospace, monospace">-swift-version 3</font> mode.</div><div>However, as for C) and D), I don't think it's worth to keep them even in Swift3 mode, because they are obviously wrong.</div><div><br></div><div>What do you think? Do we need accept them in Swift3 mode?</div></div>