<div>Sorry this is long, but it's a somewhat complicated issue that I think someone who knows a lot about is() could solve very quickly. I hit this a while back but didn't figure out exactly what the issue was until today. It seems that std.typecons.scoped doesn't play nice with interfaces:</div>
<div><br></div><div>scopedtest.d (shortened somewhat):</div><div><div>import std.typecons, std.stdio;</div><div><br></div><div>class A {</div><div>this() { writeln("A"); }</div><div>~this() { writeln("~A"); }</div>
<div>}</div><div><br></div><div>interface Bob {}</div><div><br></div><div>class ABob : A, Bob {</div><div>this() { writeln("ABob"); }</div><div>~this() { writeln("~ABob"); }</div><div>}</div><div><br>
</div>
<div>void main() { auto abob = scoped!ABob(); }</div></div><div><br></div><div><br></div><div>compiler output:</div><div><div>$ gdc -o scopedtest scopedtest.d </div><div>/usr/include/d2/4.6.0/std/typecons.d:2571: Error: template std.typecons.destroy(T) if (is(T == class)) does not match any function template declaration</div>
<div>/usr/include/d2/4.6.0/std/typecons.d:2571: Error: template std.typecons.destroy(T) if (is(T == class)) cannot deduce template function from argument types !()(A,Bob)</div><div>/usr/include/d2/4.6.0/std/typecons.d:2530: Error: template instance std.typecons.destroy!(ABob) error instantiating</div>
<div>scopedtest.d:18: instantiated from here: scoped!(ABob,)</div><div>scopedtest.d:18: Error: template instance std.typecons.scoped!(ABob,) error instantiating</div><div><br></div><div><br></div><div>std.typecons.destroy:</div>
<div><div>/*</div><div> Used by scoped() above. Calls the destructors of an object</div><div> transitively up the inheritance path, but work properly only if the</div><div> static type of the object (T) is known.</div>
<div> */</div><div>private void destroy(T)(T obj) if (is(T == class))</div><div>{</div><div> static if (is(typeof(obj.__dtor())))</div><div> {</div><div> obj.__dtor();</div><div> }</div><div> static if (!is(T == Object) && is(T Base == super))</div>
<div> {</div><div> Base b = obj;</div><div> destroy(b); // <-- this instantiation is failing</div><div> }</div><div>}</div></div><div><br></div><div><br></div></div><div>So it looks like instead of a single type, we're getting a tuple of some sort because ABob has multiple "superclasses" ? I haven't played with tuples enough to know exactly what's going on here.</div>