[Issue 4595] [tdpl] Accessing non-static member of a null reference compiles

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 17 12:54:36 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=4595



--- Comment #13 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-09-17 12:54:33 PDT ---
(In reply to comment #12)
> Failing unittest in TDPL:
> 
> unittest
> {
>   class A { int x; }
>   A a;
>   assert(!__traits(compiles, a.x = 5));
> }
> 
> Such programs must be statically rejected, guaranteed if there's no intervening
> flow in between definition and first use. We can work on improving that later,
> but for now let's get the obvious case out of the way.

After a few years of D use, I actually find the above will create problems. We
often use traits like these to check whether something is compilable, even if
the object is left uninitialized. 

For example if you want to check whether method "foo" of object "c" is callable
with an int type:

static assert(__traits(compiles, c.foo(1)));

Making this fail now because of flow analysis could hurt code that does
unittesting.

I think a runtime exception is sufficient right now, and the OP feature could
be part of some specialized flow-analysis tool.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list