[Issue 10536] New: std.typecons.wrap doesn't work with a class that defines opCast

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 4 00:47:35 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10536

           Summary: std.typecons.wrap doesn't work with a class that
                    defines opCast
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2013-07-04 00:47:34 PDT ---
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
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list