www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10219] New: Implicit conversion between delegates returning a class and an interface

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

           Summary: Implicit conversion between delegates returning a
                    class and an interface
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-05-31
21:55:56 MSD ---
---
interface I { }
class C: I { }

void f(I delegate(C) del)
{
    C c = new C;
    void* cPtr = cast(void*) c;
    void* iPtr = cast(void*) cast(I) c;
    void* delPtr = cast(void*) del(c);
    assert(cPtr != iPtr);
    assert(cPtr != delPtr); // fails
    assert(iPtr == delPtr); // fails
}

// Incorrect implicit conversion example
static assert(!__traits(compiles, f(delegate C(C c) { return c; }))); // fails

void main()
{
    // As a result wrong code is generated for lambdas
    f(c => c); // creates delegate C(C), not I(C)
}
---

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