digitalmars.D - Strange "Statement is not reachable"
- Orgoton (35/35) Mar 23 2007 I created and Actor Class like this:
- Orgoton (7/7) Mar 23 2007 Fergot to post:
- Ary Manzana (6/49) Mar 23 2007 I think this is caused because the semantic pass adds a return statement...
- Orgoton (2/2) Mar 24 2007 I have other functions and constructors with return statements and none ...
I created and Actor Class like this: class Actor { public this() { frameQ[this.type].add(this); //add myself to the queue HP=this.MaxHP; MP=this.MaxMP; if (this.type==ActorType.Other) return; if (heartQ[0].size()>heartQ[1].size()) heartQ[1].add(this); else heartQ[0].add(this); if (this.type==ActorType.Creature) AIQ.add(this); return; /*****/ } public final static const ActorType type=ActorType.Other; } (ignore functions calls, they aren't relevant) and then on the Player Class public class Player : Actor { public this(float x, float y, ubyte level) { this.level=level; super(x, y); } public final static const ActorType type=ActorType.HumanPlayer; } Now the problem lies on the line marked with "***" (the return statement in Actor's ctr). If it is there, DMD says that "statement is not reachable" without giving me any information on why or which line: semantic2 actor semantic3 actor warning - Error: statement is not reachable Process terminated with status 1 (0 minutes, 0 seconds) 0 errors, 0 warnings So, if I remove the "return;", the program compiles fine. What happened? Btw, it is my (Assembly) programming habit to put a "return;" at the end of every function, even if it is not void or is unreachable.
Mar 23 2007
Fergot to post: public this(in float x, in float y) { coord.x=x; coord.y=y; this(); } on the Actor class... Whether or not this functions has a "return;" at the end, the problem occurs.
Mar 23 2007
Orgoton escribió:I created and Actor Class like this: class Actor { public this() { frameQ[this.type].add(this); //add myself to the queue HP=this.MaxHP; MP=this.MaxMP; if (this.type==ActorType.Other) return; if (heartQ[0].size()>heartQ[1].size()) heartQ[1].add(this); else heartQ[0].add(this); if (this.type==ActorType.Creature) AIQ.add(this); return; /*****/ } public final static const ActorType type=ActorType.Other; } (ignore functions calls, they aren't relevant) and then on the Player Class public class Player : Actor { public this(float x, float y, ubyte level) { this.level=level; super(x, y); } public final static const ActorType type=ActorType.HumanPlayer; } Now the problem lies on the line marked with "***" (the return statement in Actor's ctr). If it is there, DMD says that "statement is not reachable" without giving me any information on why or which line: semantic2 actor semantic3 actor warning - Error: statement is not reachable Process terminated with status 1 (0 minutes, 0 seconds) 0 errors, 0 warnings So, if I remove the "return;", the program compiles fine. What happened? Btw, it is my (Assembly) programming habit to put a "return;" at the end of every function, even if it is not void or is unreachable.I think this is caused because the semantic pass adds a return statement at the end of the constructor, so if you specify a return you get two return statements, one of which is not reachable. But this is just a guess because I've just snooped the semantic code. Ary
Mar 23 2007
I have other functions and constructors with return statements and none other gives out the same error. Besides, it is strange that the DMD does not supply me with information as to where the error occurs (in this case, which line is unreachable). Furthermore, the compiling log shows at the end: "0 warnings, 0 errors" when there were at least one, but this may be related to Code::Blocks.
Mar 24 2007