Misleading errors when compiling

Kevin

Well-Known Member
Licensed User
Longtime User
I can't find the original thread, but I remember talking about getting misleading (or just unhelpful) error messages when compiling. Erel had asked for an example and I ran into one today.

I had commented out a sub but I accidentally left the End Sub statement in. When I compiled, I got the error:

Compiling code. Error
Error parsing program.
Error description: Stack empty.
Occurred on line: 676
End Sub

This one was really easy to spot, but there have been other times where it was a bit more difficult to find the problem.

In this case, I would probably expect something along the lines of "End Sub without Sub declaration". I imagine it would be a huge task to cover for all types of mistakes, but...... :eek:
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I had this very error the other day and was confused for about a half hour. I had been testing Event Subs with typing "Sub" then Space, Tab and accidentally left a sub all by itself in the code. I switched to another module and was coding for a while then all of a sudden the code highlighting went nuts. It was doing strange stuff, so I thought there was some kind of glitch or B4A ran out of memory or something. When I restarted B4A all modules had code in red. I was freaking out thinking I had somehow corrupted my project file.

I then decide to compile just to see what would happen and got that error. I wasn't aware of the wiki, and it was actually opposite in my case, but knowing a stack is usually used in subs/functions for keeping and passing parameters I figured something was wrong with a sub and finally found my lonely sub line. The main thing I thought odd was how one module error caused highlighting issues in all modules. A better error would have said Error Parsing ModuleName instead of Program.
 

Kevin

Well-Known Member
Licensed User
Longtime User
I've had strange code highlighting problems myself, and often times it has happened without something actually wrong with the code. Every time it happens I try to duplicate it so I can report it but I either can't get it to repeat or I can't remember exactly what I had done.

Just the other day I had copied a sub and pasted it above the original one and suddenly it showed all of the variables as undeclared even though they were. I fixed the incorrect colors by going over each variable. I forget exactly what I did but one by one they returned to the proper color for a declared variable.

I've seen quite a few different glitches like this but as I said, I can't duplicate them.
 

Kevin

Well-Known Member
Licensed User
Longtime User
Because I can be sloppy sometimes, I got another one. This one was a bit more tricky to figure out and is probably a good example of a really misleading error...

Compiling code. Error
Error compiling program.
Error description: Unknown member: enabled
Occurred on line: 406
chkShowOnNow.Enabled = True : chkShowOnNow.Text = "Show 'On Now' info in notification"
Word: enabled

The line in question:
B4X:
chkShowOnNow.Enabled = True : chkShowOnNow.Text = "Show 'On Now' info in notification"

The actual cause (which was actually on line 631):


B4X:
Sub chkShowOnNow
 '.... Sub contents
End Sub


' I forgot the _Click part for the checkbox click event through a copy/paste mishap!


Sub chkShowOnNow_Click
 '.... Sub contents
End Sub

So apparently that mistake caused the compiler to think chkShowOnNow was a sub rather than a checkbox. :eek:
 
Top