www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 210] New: Strange results when covariantly implementing an interface method defined with an interface return type

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=210

           Summary: Strange results when covariantly implementing an
                    interface method defined with an interface return type
           Product: D
           Version: 0.160
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: smjg iname.com
OtherBugsDependingO 179
             nThis:


This bug carries on where issue 65 left off.  That issue covered the case where
the interface-to-class covariance is in a class-to-class override.  This one
covers interface-to-class covariance in an interface-to-class override.

This was originally intended to be part of issue 65, but I figured that it
might make more sense to break it off as a separate issue.

Testcases, based on issue 179 comment 1:

----------
import std.stdio;

interface Father {
    Father test();
    void showData();
}

class Child : Father {
    int data;

    this(int d) { data = d; }

    Child test() { 
        writefln("in CovFunc Test");
        return new Child(69);
    }

    void showData() {
        writefln("Child: %d", data);
    }
}

void icov2test() {
    Child aChild = new Child(42);
    aChild.showData();

    Father childsDad = aChild;
    childsDad.showData();

    Father dadTest = childsDad.test;
    writefln("FCALL dadTest.showData");
    dadTest.showData();
    writefln("FCALL dadTest.test");
    dadTest.test();
    writefln("FCALL (cast(Child) dadTest).showData");
    (cast(Child) dadTest).showData();
}
----------
import std.stdio;

interface IFoo {
}

interface ICov {
    IFoo covfunc();
}

class Child : ICov, IFoo {
    Child covfunc() { 
        writefln("in CovFunc Test");
        return new Child();
    }
}

void icov3() {
    ICov icov = new Child();

    IFoo ifoo = icov.covfunc();
    writefln(ifoo.classinfo.name); // Segfault or prints garbage
    writefln((cast(Object) ifoo)); // Segfault or prints garbage

}
----------
import std.stdio;

interface IFoo {
    IFoo covfunc();
}

class Child : IFoo {
    Child covfunc() { 
        writefln("in CovFunc Test");
        return new Child();
    }
}

void icov3() {
    IFoo icov = new Child();

    IFoo ifoo = icov.covfunc();
    writefln(ifoo.classinfo.name);
    writefln((cast(Object) ifoo));

}
----------

There are other cases to test, namely those involving interface-to-interface
covariance || an interface-to-interface override.  But getting the above tests
working would be a start.


-- 
Jun 19 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=210


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from bugzilla digitalmars.com  2006-06-30 20:31 -------
Fixed DMD 0.162


-- 
Jun 30 2006