[Issue 2274] all static if typeof seriously wrong
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 7 18:33:49 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274
------- Comment #5 from someanon at yahoo.com 2008-08-07 20:33 -------
(In reply to comment #4)
> I can't agree with you. The binary generated is perfectly valid. It never
> crashes, it behaves just like intended. The fact alone that you expect
> different result doesn't mean the executable is broken.
>
> Your static if check is not passed, that's all.
>
> If you expect to see the following output:
> test.A:+ test.B:+ test.C:- int:-
>
> then you should change your code. You are not allowed to access non-static data
> via class name like this:
> bool result = is(typeof(E.toString()) : string); // false unless toString is
> static
>
> or like this:
> bool result = is(typeof(E.myInt) : int);
>
> You have to create a class instance, first:
> auto e = new E();
> bool result = is(typeof(e.toString()) : string); // true for any class unless
> toString is private
>
> or, better, in one line:
> bool result = is(typeof((new E()).toString()) : string);
>
> Note that no allocation will take place in latter case since it is merely a
> check.
>
> Shall we consider an issue closed by now?
Thanks for your answer, but No. When you give an answer please test it: (with
v2.017 on Linux)
If I change the test code as you suggested:
static if (is((new E()).toString()) : string) { // regardless of 'static'
$ dmd t.d
t.d(18): basic type expected, not (
t.d(18): found 'new' when expecting ')'
t.d(18): found 'E' when expecting ')'
t.d(18): found ')' when expecting ';' following 'statement'
t.d(18): found ':' instead of statement
t.d(20): Declaration expected, not 'else'
t.d(23): Declaration expected, not 'return'
t.d(24): unrecognized declaration
BTW, I need static test, because inside '{}' I will do something with the
method/attribute.
--
More information about the Digitalmars-d-bugs
mailing list