Page 1 of 1
Compiler error not entirely helpful
Posted: Mon Jul 02, 2007 9:28 pm
by Mistrel
My compiler spat out this error to me today:
Line 8: The following end condition is missing: Endif
I looked for a few minutes at all of my If statements and couldn't figure out what was wrong. It ended up being that the compiler was correct in that it didn't run into said Endif but it was in fact where it was supposed to be.
The error was that I had used a EndProcedure instead of a ProcedureReturn.
Even though the compiler was stating fact the error was confusing to me.
Here is an example:
Code: Select all
Declare this()
this()
Procedure this()
If a=1
EndProcedure
EndIf
EndProcedure
Re: Compiler error not entirely helpful
Posted: Mon Jul 02, 2007 9:58 pm
by PB
Not a bug, and the error is entirely helpful and correct.
The compiler thinks the first "EndProcedure" is the end of the procedure, but
since you didn't have "EndIf" before it (to end the "a=1" part), the error given
is correct. Stick an "EndIf" there and it fixes the problem, but obviously leads
to further errors because then you'll have another "EndIf" without "If".
Remember, PureBasic compiles from top-down, in one pass. It's up to you to
ensure everything that is opened, is closed (so to speak), and in order.
Posted: Mon Jul 02, 2007 10:10 pm
by Mistrel
You're right. I'm guess that I'm going to have to get used to this whole one-pass thing. :roll:
Posted: Mon Jul 02, 2007 10:50 pm
by Dare
Although I don't think that this is just a one pass issue.
You are defining the start and the end of a procedure and then the end of another procedure where the start has not yet been defined.
The compiler would have to try to guess what you intended. For example:
Code: Select all
Declare this()
this()
Procedure this()
If a=1
EndProcedure ; Meant to type something else
EndIf
EndProcedure
or this
Code: Select all
Declare this()
this()
Procedure this()
If a=1 ; Forgetting to type the rest
EndProcedure
Procedure Another() ; Forgetting to type this and a bit more
EndIf
EndProcedure
or something else altogether.
Regardless of how many times it ran through this it still has to try to guess what you were doing.
Or just do as it did, see the EndProcedure and say "heya, missing EndIf inside this proc, buddy!". Which is true.
Posted: Mon Jul 02, 2007 10:58 pm
by Kaeru Gaman
for me it helps to add the EndProcedure-command just after the Procedure-command, using the autocomplete feature.
when I typed "Proc" I hit TAB twice, and the IDE will complete "Procedure" and insert "EndProcedure" behind the cursor.
then I insert the code of the proc in between, so I can neither forget the end nor type it twice by accident...