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 ----
Comment #1 by k.hara.pg — 2013-07-04T01:10:18Z
Comment #2 by github-bugzilla — 2013-09-26T05:55:07Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/830b6c1bd4cd465766c3d5b873c3c9838e16fc15 fix Issue 10536 - std.typecons.wrap doesn't work with a class that defines opCast https://github.com/D-Programming-Language/phobos/commit/36aa69b5ff06980dca4e31df046c122a50f75c22 Merge pull request #1386 from 9rnsr/fix_wrap Issue 10536 & 10538 - std.typecons.wrap/unwrap bug fix and improvement