Compiler error not entirely helpful

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Compiler error not entirely helpful

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Compiler error not entirely helpful

Post by PB »

Not a bug, and the error is entirely helpful and correct. :P

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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

You're right. I'm guess that I'm going to have to get used to this whole one-pass thing. :roll:
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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.
Dare2 cut down to size
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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...
oh... and have a nice day.
Post Reply