Strange "Statement is not reachable"
Ary Manzana
ary at esperanto.org.ar
Fri Mar 23 05:51:24 PDT 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
More information about the Digitalmars-d
mailing list