NotNull Parser

bearophile bearophileHUGS at lycos.com
Fri Aug 3 05:06:04 PDT 2012


Timon Gehr:

> The notation 'T?' is normally used for a nullable type.

Right. that's why I have suggested a trailing "@":
http://d.puremagic.com/issues/show_bug.cgi?id=4571

------------------------

Namespace:

> void foo(Object? o) {
> 	// do something with o
> }
> [/code]
> 		
> will convert into
>
> [code]
> void foo(Object o, string filename = __FILE__, uint line =
> __LINE__) in {
> 	if (o is null) throw new Exception("Object is null.", filename,
> line);
> } body {
> 	// do something with o
> }
> [/code]

Object@ is a type, so if you write:

void foo(Object@ o) {...

It means the compiler statically refuses you to give a nullable 
type to foo. So inside foo there is no need for a run time test.

Good work :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list