Author Topic: Function calls incorrectly allow parentheses around array arguments  (Read 12759 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
So here's a nice little snippet of code to make QB64 puke at you:

Code: QB64: [Select]
  1. foo (array())
  2.  
  3. SUB foo (array())

Can't get much simpler than that!  Just call a sub, send it an array....   Watch it die a horrible death. 

C compilation fail!  No good messages for you!  :P

What's even better is if you open up the error log and see what c has to tell you:

Quote
In file included from qbx.cpp:2154:
..\\temp\\maindata.txt: In function 'void QBMAIN(void*)':
..\\temp\\maindata.txt:13:2: error: 'pass1' was not declared in this scope
  pass1;
  ^~~~~
compilation terminated due to -Wfatal-errors.

Welp, I guess that cleared that whole mess up... 

pass1?  Where'd that come from?  What made it?  Why's it there?  What's it supposed to be for?  WHAT THE BLEEEEEP!!  There's nothing called PASS in the routine, and there's no loops or error checking required....   

/sigh

And all because we wrapped our parameter in brackets:

foo (array())

Remove those and all are good.  Leave them, and (if you're like me), you'd spend hours tearing your code apart trying to figure out "just what the BLEEP did I go wrong??!"
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A (bug())
« Reply #1 on: August 26, 2019, 07:53:36 pm »
Shoulda called it:
Code: QB64: [Select]
  1. CALL foo(array())
  2.  
  3. SUB foo (array())
  4.  

Sorry, you are probably not in mood for jokes... it is weird bug, works fine if it were just a number.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A (bug())
« Reply #2 on: August 27, 2019, 07:39:58 am »
Shoulda called it:
Code: QB64: [Select]
  1. CALL foo(array())
  2.  
  3. SUB foo (array())
  4.  

Sorry, you are probably not in mood for jokes... it is weird bug, works fine if it were just a number.

Aye, and it’s one I even knew about, and was warning Qwerty about the other day.  (At least I think it was him.  With my memory, it might’ve been all just a dream...). 

Qwerty was wanting a way to pass variables to subs, by reference, and had discovered that wrapping them in parentheses worked.  I warned him, “not in all cases”, but I couldn’t remember those chases where it failed...

... And now, a few weeks later, I make a silly, distracted typo, and get this mess.  My first thought was, “Oh shit! What have I broken in QB64, pushing the changes to ZLIB and the console into the language?!”

An hour of debugging later, I can’t fathom anything that I’d altered which might cause the glitch...

Another hour of deconstructing code a line at a time, finally let’s me zero in on the lines that generated it...  Still though, my eyes didn’t pick up on that extra set of parentheses, and the IDE happily says, “OK”...

So I dig back into the QB64 source to hunt for the root of the issue...

Another hour or so...

Screw it!  I’m off for lunch!!

....Come back and it’s OBVIOUS to me now, that I have extra brackets around that array...

...And I slap myself hard upside the head and cuss so loudly, it sends my dog into a barking fit to warn off the danger. 

/sigh

Some days, I wonder why I ever even bothered to learn programming.  “Joys of programming, my ass!”
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: A (bug())
« Reply #3 on: August 27, 2019, 08:54:48 am »
This is simply a case of the syntax checker missing an invalid line. It happens from time to time. Blame the ad-hoc parser/checker.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Function calls incorrectly allow parentheses around array arguments
« Reply #4 on: August 27, 2019, 09:04:06 am »
When I started reading this post, I thought "Steve was warning me of this problem the other day".  So, yep it was me.

Qwerkey (and my mnemonic cousin Qwerty sends his best regards).

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Function calls incorrectly allow parentheses around array arguments
« Reply #5 on: August 27, 2019, 12:07:34 pm »
doesn't complain with this
Code: [Select]
foo (array())

SUB foo (array)
END SUB

however it thinks that just cause you have () around the variable its a array, so even
foo (a)
is considered an array for some reason, cause if you just put
foo a
it complains that you must supply and array. "Expected arrayname()"

Not sure that helps with anything or just compounds things.
Granted after becoming radioactive I only have a half-life!