<div dir="ltr">In trying to implement a COW type, but I'm running into problems with isUniqueReferenced breaking in even fairly simple cases. For example (with -O) the code below prints <span style="color:rgb(153,18,1);font-family:Menlo;font-size:11px">"bar: false"</span>, commenting out the print in <font face="monospace, monospace">test()</font> makes it print <span style="color:rgb(153,18,1);font-family:Menlo;font-size:11px">"bar: true"</span>, and removing the var parameter <span style="font-family:Menlo;font-size:11px;color:rgb(2,35,192)">var</span><span style="color:rgb(66,66,66);font-family:Menlo;font-size:11px"> foo: </span><span style="font-family:Menlo;font-size:11px;color:rgb(26,178,173)">Foo</span> and using <span style="font-family:Menlo;font-size:11px;color:rgb(2,35,192)">var</span><span style="color:rgb(66,66,66);font-family:Menlo;font-size:11px"> foo = foo</span> instead breaks it again. Am I doing something wrong here?<div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="color:rgb(2,35,192)">class</span><span style=""> FooStorage { </span><span style="color:rgb(2,35,192)">var</span><span style=""> x: </span><span style="color:rgb(26,178,173)">Int</span><span style=""> = </span><span style="color:rgb(50,51,51)">0</span><span style=""> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66);min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="color:rgb(2,35,192)">struct</span><span style=""> Foo { </span><span style="color:rgb(2,35,192)">var</span><span style=""> storage = FooStorage() }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66);min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="color:rgb(2,35,192)">func</span><span style=""> bar(</span><span style="color:rgb(2,35,192)">var</span><span style=""> foo: </span><span style="color:rgb(26,178,173)">Foo</span><span style="">) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style=""><span class="" style="white-space:pre">        </span>print(</span><span style="color:rgb(153,18,1)">"bar: </span><span style="">\</span><span style="color:rgb(153,18,1)">(</span><span style="">isUniquelyReferencedNonObjC(&foo.storage)</span><span style="color:rgb(153,18,1)">)"</span><span style="">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66);min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="color:rgb(2,35,192)">func</span><span style=""> test() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style=""><span class="" style="white-space:pre">        </span></span><span style="color:rgb(2,35,192)">var</span><span style=""> foo = Foo()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(66,66,66)"><span class="" style="white-space:pre">        </span>print(</span><span style="color:rgb(153,18,1)">"test: </span><span style="color:rgb(66,66,66)">\</span><span style="color:rgb(153,18,1)">(</span><span style="color:rgb(66,66,66)">isUniquelyReferencedNonObjC(&foo.storage)</span><span style="color:rgb(153,18,1)">)"</span><font color="#424242">)</font></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style=""><span class="" style="white-space:pre">        </span>bar(foo)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66);min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(66,66,66)"><span style="">test()</span></p></div></div>