D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6503 - std.typecons.scoped fails to instantiate for classes that inherit from interfaces
Summary: std.typecons.scoped fails to instantiate for classes that inherit from interf...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-16 00:40 UTC by Andrew Wiley
Modified: 2011-08-16 16:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrew Wiley 2011-08-16 00:40:11 UTC
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.
Comment 1 Andrew Wiley 2011-08-16 16:01:20 UTC
Fix merged
https://github.com/D-Programming-Language/phobos/pull/199