[article] Language Design Deal Breakers
Diggory
diggsey at googlemail.com
Tue May 28 22:56:22 PDT 2013
On Wednesday, 29 May 2013 at 05:35:14 UTC, Walter Bright wrote:
> On 5/28/2013 9:55 PM, Diggory wrote:
>> As a last resort there should be a runtime check available
>> such as
>> assertNotNull(T) which does the conversion.
>
> The idea is to put the check on assignments to NotNull, not on
> usage of it.
I know, that's what my suggestion was for.
assertNotNull(T) would return a NotNull!T given a T (probably
should have explained that)
The reason for that, as opposed to checking in the assignment
operator is that it's possible to assign to a variable without
knowing that it's supposed to be NotNull:
someVar.someProperty = normalPtr; // Won't detect this at compile
time
If "assertNotNull(T)" is needed then it's obvious:
someVar.someProperty = assertNotNull(normalPtr)
And without it the compiler can issue an error message.
If there's no compile time detection of problems then there's no
point using NotNull, you're just replacing null pointer
exceptions by a different exception.
More information about the Digitalmars-d
mailing list