Bug 6503 – std.typecons.scoped fails to instantiate for classes that inherit from interfaces
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-16T00:40:00Z
Last change time
2011-08-16T16:01:20Z
Assigned to
nobody
Creator
debio264
Comments
Comment #0 by debio264 — 2011-08-16T00:40:11Z
code sample:
import std.typecons, std.stdio;
class A {
this() { writeln("A"); }
~this() { writeln("~A"); }
}
interface Bob {}
class ABob : A, Bob {
this() { writeln("ABob"); }
~this() { writeln("~ABob"); }
}
void main() { auto abob = scoped!ABob(); }
ABob is just a normal class, and creating an instance of it on the stack shouldn't be a problem, but scoped fails to instantiate because std.typecons.destroy fails to instantiate:
/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
/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)
/usr/include/d2/4.6.0/std/typecons.d:2530: Error: template instance std.typecons.destroy!(ABob) error instantiating
scopedtest.d:18: instantiated from here: scoped!(ABob,)
scopedtest.d:18: Error: template instance std.typecons.scoped!(ABob,) error instantiating
This error is interesting:
cannot deduce template function from argument types !()(A,Bob)
it looks like we're getting some sort of tuple of ABob's superclasses, trying to instantiate destroy on it, and failing.
The correct behavior should be to special case classes that implement interfaces so the interfaces are ignored when figuring out how to call destructors.