Bug 9340 – Covariant return type conflicts with out contract.

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-17T14:55:00Z
Last change time
2013-07-18T01:41:09Z
Assigned to
nobody
Creator
adrian

Comments

Comment #0 by adrian — 2013-01-17T14:55:58Z
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()); }
Comment #1 by k.hara.pg — 2013-07-18T01:41:09Z
*** This issue has been marked as a duplicate of issue 10479 ***