Comment #0 by snarwin+bugzilla — 2023-10-07T17:00:06Z
As of DMD 2.104.0, the following program fails to compile:
---
class X {}
class A : X {}
class B : X {}
auto fun(bool b)
{
if (b) return new A;
else return new B;
}
---
The error message is:
---
example.d(8): Error: expected return type of `example.A`, not `example.B`:
example.d(7): Return type of `example.A` inferred here.
---
Since A and B have an unambiguous common type, X, the compiler should infer the return type of fun to be X.
Comment #1 by razvan.nitu1305 — 2023-10-09T12:05:55Z
*** This issue has been marked as a duplicate of issue 16194 ***