<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 was writing some code that would allow transformations of values as part of an expression, and I came across a strange error:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(146, 146, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">/// Returns the operand after a given transformation.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(146, 146, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">///</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(146, 146, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">/// Example: `let newRect = myRect << { $0.origin.x += 3 }`</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> << <T> (given: </span><span style="font-variant-ligatures: no-common-ligatures; color: #498672" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">, transformation: (inout </span><span style="font-variant-ligatures: no-common-ligatures; color: #498672" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> ()) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #498672" class="">T</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result = given</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>transformation(&result)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">let</span> volume = component.volume << { $0.ranges.z.width = <span style="font-variant-ligatures: no-common-ligatures; color: #da2000" class="">0</span> } // Error: Expression type () is ambiguous without more context.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> volume = component.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">volume</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class=""><<</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { $0.ranges.z.width = </span><span style="font-variant-ligatures: no-common-ligatures; color: #da2000" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">; </span><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> () } // Error: Cannot assign to property: ‘$0’ is immutable.</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">let</span> volume = component.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">volume</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class=""><<</span> { (x: <span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">inout</span> <span style="font-variant-ligatures: no-common-ligatures; color: #498672" class="">SCNBoxVolume</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #008f01" class="">in</span> x.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ranges</span>.z.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">width</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #da2000" class="">0 </span>} // Succeeds!</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Obviously, this code could easily create a var for volume and mutate it, but it doesn’t solve my problem. Am I misunderstanding how this could work? This is the only overload of << that accepts a closure, and even the code completion recognizes that $0 is a SCNBoxVolume. It’s just strange that the compiler won’t recognize $0 as an inout parameter off the bat.</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Is this a bug, or a design choice?</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></span></div></body></html>