Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 07, 2008 [Issue 2274] New: all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2274 Summary: all static if typeof seriously wrong Product: D Version: 2.017 Platform: PC OS/Version: Linux Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: someanon@yahoo.com each of line 16, 17, 18 in attached file t.d when comment off, will generate an error. line 16: // wrong: t.A:- t.B:+ t.C:- int:- line 17: // wrong: t.A:- t.B:- t.C:- int:- line 18: // wrong: t.A:- t.B:- t.C:- int:- I wonder if anyone ever used static if typeof at all. -- |
August 07, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 ------- Comment #1 from someanon@yahoo.com 2008-08-07 16:04 ------- Created an attachment (id=266) --> (http://d.puremagic.com/issues/attachment.cgi?id=266&action=view) the source file -- |
August 07, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 2korden@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE ------- Comment #2 from 2korden@gmail.com 2008-08-07 18:51 ------- no need for posting twise, you already reported an issue earlier. *** This bug has been marked as a duplicate of 2154 *** -- |
August 08, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 someanon@yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|DUPLICATE | ------- Comment #3 from someanon@yahoo.com 2008-08-07 19:13 ------- No, this is not DUPLICATE. That one is that the compiler doesn't accept the code. This one, is the binary generated behaves wrong. -- |
August 08, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 ------- Comment #4 from 2korden@gmail.com 2008-08-07 19:42 ------- 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? -- |
August 08, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 ------- Comment #5 from someanon@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. -- |
August 08, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 someanon@yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution| |FIXED ------- Comment #6 from someanon@yahoo.com 2008-08-07 20:41 ------- sorry I got it wrong: it should be static if (is(typeof((new E()).toString()) : string)) {..} Now the code compiles, and runs correctly. Thanks for the reply. -- |
August 08, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 ------- Comment #7 from someanon@yahoo.com 2008-08-07 21:23 ------- Hold on, one more issue: in the original file line 16: // wrong: t.A:- t.B:+ t.C:- int:- Why an empty class B{} pass the test? it has a static toString? -- |
August 08, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 ------- Comment #8 from 2korden@gmail.com 2008-08-08 06:13 ------- Yes, it inherits it from Object. -- |
August 09, 2008 [Issue 2274] all static if typeof seriously wrong | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2274 ------- Comment #9 from someanon@yahoo.com 2008-08-08 23:39 ------- (In reply to comment #8) > Yes, it inherits it from Object. > /dmd/src/phobos/object.d class Object { void print(); string toString(); // you mean this one? hash_t toHash(); int opCmp(Object o); bool opEquals(Object o); final void notifyRegister(void delegate(Object) dg); final void notifyUnRegister(void delegate(Object) dg); static Object factory(string classname); } How it pass the static test in my original code? Shall we reopen the bug? ;-) -- |
Copyright © 1999-2021 by the D Language Foundation