digitalmars.D.bugs - [Issue 2274] New: all static if typeof seriously wrong
- d-bugmail puremagic.com (19/19) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (6/6) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (10/10) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (11/11) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (24/24) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (19/48) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (12/12) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (6/6) Aug 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (4/4) Aug 08 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (18/20) Aug 08 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (10/10) Aug 10 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2274
- d-bugmail puremagic.com (23/26) Nov 23 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2274
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. --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 Created an attachment (id=266) --> (http://d.puremagic.com/issues/attachment.cgi?id=266&action=view) the source file --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 2korden gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE no need for posting twise, you already reported an issue earlier. *** This bug has been marked as a duplicate of 2154 *** --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 someanon yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|DUPLICATE | No, this is not DUPLICATE. That one is that the compiler doesn't accept the code. This one, is the binary generated behaves wrong. --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 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? --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274I 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. --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 someanon yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution| |FIXED 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. --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 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? --
Aug 07 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 Yes, it inherits it from Object. --
Aug 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274Yes, 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? ;-) --
Aug 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 someanon yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED | line 16: // wrong: t.A:- t.B:+ t.C:- int:- Why an empty class B{} pass the test? --
Aug 10 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2274 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED CC| |clugdbug yahoo.com.au Resolution| |INVALIDline 16: // wrong: t.A:- t.B:+ t.C:- int:- Why an empty class B{} pass the test?Because it has toString(). Try this code: --- import std.stdio; class B {} void main() { B b = new B; writefln(b.toString()); } --- There's no bug here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 23 2009