Adding the ?. null verification
Lionello Lunesu via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 18 19:26:14 PDT 2014
On 19/06/14 00:17, Etienne wrote:
>> I want non-null in the type system! To put a nullable reference into a
>> non-null variable you need to check first, but from then on the compiler
>> can ensure it's never null!
>
> That would be great but useless for my situation involving some complex
> AST's
>
> class AEntity
> {
> Module head;
> string ident;
> Type type;
> AEntity typeInfo;
> AEntity[] members; // for definitions
> AEntity[] parameters; // if parameterized
> ...
> }
>
> It's very useful to descend through parts of a complex tree without
> adding plenty of bool checks
>
> foreach (AEntity member; entity.members)
> {
> if (member.typeInfo !is null)
> {
> AEntity curr = member;
> member.ident ~= member.typeInfo.ident;
> curr = member.typeInfo;
> while (curr.typeInfo !is null)
> {
> member.ident ~= "." ~ curr.typeInfo.ident;
> curr = curr.typeInfo;
> }
> }
> }
And all of those references can be null at any time? Non-null would
force you to initialize some/all of those values to a non-null
reference, with the compiler ensuring that that is really the case.
More information about the Digitalmars-d
mailing list