On 07/14/2017 03:06 PM, Lurker wrote:
On Friday, 14 July 2017 at 15:39:01 UTC, Guillaume Boucher wrote:
Example 1: Polymorphism
class Bird { void fly() { ... } };
class Penguin : Bird { override void fly() @pragma(noreturn) {
assert(0); } };
class EvolvedPenguin : Penguin { override void fly() { ... } };
No matter how you look at it, this code should simply not be allowed:
Bird bird = ...;
bird.fly(); // is this return or noreturn?
Penguin penguin = ...;
penguin.fly(); // is this return or noreturn?
In both cases, compiler cannot draw any conclusions about
return/noreturn and thus I believe such code should not be allowed.
Conventional thinking has it that derived methods should "require less
and deliver more" such that substitution is possible. That's where
contravariant parameters and covariant returns come from. Therefore,
methods that do not return should be able to override those that return.
(The opposite is unworkable btw.) Note that the absence of a "noreturn"
annotation does not imply a guarantee that the method does return.
Andrei