www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9340] New: Covariant return type conflicts with out contract.

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

           Summary: Covariant return type conflicts with out contract.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: epi atari8.info


--- Comment #0 from Adrian Matoga <epi atari8.info> 2013-01-17 14:55:58 PST ---
The following test case fails to compile with the following error message:
test.d(21): Error: cast(const(BaseBar))__result is not an lvalue
Comment out line (1) or change ConcreteBar to BaseBar in (2) and it compiles.
That means the workaround is to use base type in the overriding method.


import std.stdio;

class BaseBar
{
    abstract string bar();
}

class BaseFoo
{
    abstract BaseBar createBar()
    out(result) { assert(result !is null); } body { assert(false); } // (1)
}

class ConcreteBar : BaseBar
{
    override string bar() { return "ConcreteBar"; }
}

class ConcreteFoo : BaseFoo
{
    override ConcreteBar createBar() { return new ConcreteBar(); } // (2)
}

void main()
{
    auto foo = new ConcreteFoo();
    writeln(foo.createBar().bar());
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 17 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9340


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-07-18 01:41:09 PDT ---
*** This issue has been marked as a duplicate of issue 10479 ***

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