DIP 1017--Add Bottom Type--Community Review Round 1
w0rp
devw0rp at gmail.com
Thu Aug 9 15:56:31 UTC 2018
On Thursday, 9 August 2018 at 10:37:36 UTC, Andrea Fontana wrote:
> On Thursday, 9 August 2018 at 04:10:47 UTC, Nicholas Wilson
> wrote:
>> The DIP makes the claim that:
>> * "[@noreturn] has the awkward result of a function
>> specifying it has a return type T, but never returns that
>> type". When it is deliberate (such as annotating a fatal error
>> function) the is almost exclusively `void` (I know of no
>> examples to the contrary).
>
> Let's say we need to implement an interface with a int func();
> member. We can mark it with @noreturn but we can't use TBottom
> return type: we're going to break interface implementation.
>
> Andrea
It will work, and why it will work requires some understanding of
bottom types. You can define the function as `TBottom func()` and
it should work, because `TBottom` is a subtype of `int`. In the
same way you can implement `ParentClass func()` as `SubClass
func()`, because `SubClass` is a subtype of `ParentClass`.
Similarly, you can assign values of `TBottom` to `int`, because
`TBottom` is a subtype of all types, but you cannot assign `int`
to `TBottom`, because `int` is not a subtype of `TBottom`.
More information about the Digitalmars-d
mailing list