www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2814] New: implicit cast (implemented via alias this) is not triggered when passing to function

reply d-bugmail puremagic.com writes:

           Summary: implicit cast (implemented via alias this) is not
                    triggered when passing to function
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: 2korden gmail.com

struct Proxy
        private Object o;

        Object get() { return o; }

        alias get this;

void foo(Object o)

void main()
        Proxy proxy;
        //foo(proxy); // should work, but doesn't

        Object o = proxy; // workaround

test.d(17): Error: function test.foo (Object o) does not match parameter types
test.d(17): Error: cannot implicitly convert expression (proxy) of type Proxy

Apr 06 2009
parent d-bugmail puremagic.com writes:

Jarrett Billingsley <jarrett.billingsley gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |jarrett.billingsley gmail.c
                   |                            |om

--- Comment #1 from Jarrett Billingsley <jarrett.billingsley gmail.com> 
2009-08-05 18:48:39 PDT ---
Strangely, the compiler's behavior differs based on the type of the result of
get().  While the workaround works in this instance (returning Object), it
doesn't seem to work for any other type.  For instance, given this struct:

struct Proxy
    int get() { return 0; }
    alias get this;

If you do:

Proxy p;
int x = p;

you get an error saying it can't convert type Proxy to int.  But here's the
real kicker:

Object x = p;

_Now_ the compiler says that it can't convert p.get() of type int to Object! 
So for some reason, it's using the alias this when it shouldn't, and not using
it when it should.

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