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)) { }
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
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
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.
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?
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
Can you show me an example of your two options?
I'm not sure what do you exactly mean.
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
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