<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Hi,
<div><br /></div>
<div>I found a very rare situation that closure can’t infer the type of its parameter. See the code below:</div>
<blockquote style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div><font face="Menlo" size="2"><span style="background-color: rgb(255, 255, 255);">```</span></font></div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span style="color: #ba2da2">func</span> withReference&lt;T, Result&gt;(<span style="color: #ba2da2">_</span> value: <span style="color: #ba2da2">inout</span> <span style="color: #4f8187">T</span>, <span style="color: #ba2da2">_</span> execute: (<span style="color: #ba2da2">inout</span> <span style="color: #4f8187">T</span>) <span style="color: #ba2da2">throws</span> -&gt; <span style="color: #4f8187">Result</span>) <span style="color: #ba2da2">rethrows</span> -&gt; <span style="color: #4f8187">Result</span> {</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">&#160; &#160; <span style="color: #ba2da2">return</span> <span style="color: #ba2da2">try</span> execute(&amp;value)</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">}</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;"><br /></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span style="color: #ba2da2">struct</span> Person {</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">&#160; &#160; <span style="color: #ba2da2">var</span> name: <span style="color: #703daa">String</span></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">}</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;"><br /></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span style="color: #ba2da2">var</span> p = <span style="color: #4f8187">Person</span>(name: <span style="color: #d12f1b">"a"</span>)</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;"><br /></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);">withReference<span style="color: #000000">(&amp;</span><span style="color: #4f8187">p</span><span style="color: #000000">) { (v)&#160;</span> <span style="color: #ba2da2">in</span></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">&#160; &#160; v.<span style="text-decoration: underline">n</span>ame = <span style="color: #d12f1b">"1"</span></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">}</p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;"><br /></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);">print<span style="color: #000000">(</span><span style="color: #4f8187">p</span><span style="color: #000000">)</span></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">```</p>
</div>
</blockquote>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">The code can be compiled and produce correct result in Swift 3(Xcode 8) playground, but it can’t be compiled in Swift 4(Xcode 9 beta2).</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">The error says:&#160;</p>
</div>
<blockquote style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"><b>error: bug.playground:11:7: error: type of expression is ambiguous without more context</b></span></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"><b>&#160; &#160; v.name = "1"</b></span></p>
</div>
<div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"><b>&#160; &#160; ~~^~~~</b></span></p>
</div>
</blockquote>
<font face="Menlo" size="2">Is&#160;this related to exclusive access rule introduced to Swift 4?</font></div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
Regards,<br />
Yilei He</div>
</body>
</html>