Adding the ?. null verification
Etienne via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 18 09:17:33 PDT 2014
> 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;
}
}
}
More information about the Digitalmars-d
mailing list