Bug 10536 – std.typecons.wrap doesn't work with a class that defines opCast
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-04T00:47:00Z
Last change time
2013-09-26T05:55:21Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2013-07-04T00:47:34Z
std.typecons.wrap and unwrap internally uses cross-cast, but current implementation accidentally takes opCast member functions.
Code:
----
import std.typecons;
interface Interface { int foo(); }
class Pluggable {
int foo() { return 1; }
@disable void opCast(T, this X)(); // !
}
void main() {
Interface i = new Pluggable().wrap!Interface;
assert(i.foo() == 1);
}
Output:
----
std\typecons.d(2780): Error: function test.Pluggable.opCast!(inout(Object), inout(Pluggable)).opCast is not callable because it is annotated with @disable
std\typecons.d(2780): Error: pure function 'std.typecons.wrap!(Interface).wrap!(Pluggable).Impl._wrap_getSource' cannot call impure function 'test.Pluggable.opCast!(inout(Object), inout(Pluggable)).opCast'
std\typecons.d(2780): Error: cannot implicitly convert expression (this._wrap_source.opCast()) of type void to inout(Object)
test.d(16): Error: template instance std.typecons.wrap!(Interface).wrap!(Pluggable) error instantiating
----