state of an object

2012-07-01 Thread Namespace
Is it possible to figure out how is the state of an object at compile time? E.g. if the object is null or not: class Foo { } Foo f; static if (is_null(f)) { }

Re: state of an object

2012-07-01 Thread bearophile
Namespace: Is it possible to figure out how is the state of an object at compile time? E.g. if the object is null or not: class Foo { } Foo f; static if (is_null(f)) { } In general you need a tool that analyzes D code statically (and maybe in some cases doesn't give a certain a

Re: state of an object

2012-07-02 Thread Jonathan M Davis
On Monday, July 02, 2012 08:19:52 Namespace wrote: > Is it possible to figure out how is the state of an object at > compile time? > E.g. if the object is null or not: > > class Foo { } > > Foo f; > > static if (is_null(f)) { } What are you trying to test exactly? Wh

Re: state of an object

2012-07-02 Thread Namespace
In general you need a tool that analyzes D code statically (and maybe in some cases doesn't give a certain answer). Bye, bearophile Short: not so easy. Too bad.

Re: state of an object

2012-07-02 Thread Namespace
My intention was to avoid something like this: [code] class Foo { } Foo f; // f is null NotNull!(Foo) test = f; // should throw an compiler error, because f is null [/code] I can avoid NotNull!(Foo) test = null; with @disable this(typeof(null)); but how can i avoid null objects?

Re: state of an object

2012-07-02 Thread Jonathan M Davis
On Monday, July 02, 2012 10:41:03 Namespace wrote: > My intention was to avoid something like this: > > [code] > class Foo { } > > Foo f; // f is null > > NotNull!(Foo) test = f; // should throw an compiler error, > because f is null > [/code] > > I can avoid > > NotNull!(Foo) test = null; wit

Re: state of an object

2012-07-02 Thread Namespace
Can you show me an example of your two options? I'm not sure what do you exactly mean.

Re: state of an object

2012-07-02 Thread Namespace
I cannot create the Foo objects _in_ the NotNull struct because i need the reference of an specific object. And if i throw an error if the object paramter is null, it's not a compiler error. So there is no way that a null reference as paramter can be detect at compile time? I tried different __t

Re: state of an object

2012-07-02 Thread Jonathan M Davis
a null reference as paramter can be > detect at compile time? I tried different __traits but i wondered > that there is nothing like > __traits(ThrowError, { object.toString(); }) which would be > perfect to detect that cases. The state of an object is entirely a runtime artifact. Take