Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using --debug-array with arrays passed to functions
(03-09-2021, 01:11 PM)georgeo Wrote: Hi everyone,

I would like to use the --debug-array option to check I have not used out-of-range array indices in my program. However, it appears that I need to give the compiler more information, to use the option in a program that passes arrays as function arguments.

For example, the following simple program appears to compile/ run correctly:
function pickString$( choice as ubyte,  listOfStrings() as string ) as string
    return listOfStrings(choice)
end function

dim myString$(3) as string
myString$(0) = "Zero"
myString$(1) = "One"
myString$(2) = "Two"
myString$(3) = "Three"

dim n as ubyte

for n=0 to 3
    print pickString$(n, myString$)
next n


--but the compiler generates an error if I try to compile with the --debug-array option:

zxbc -t -a -B --debug-array array_bounds_ex.bas
Traceback (most recent call last):
  File "c:\opt\zxbasic-1.14.0\zxbasic\", line 10, in <module>
    sys.exit(libzxbc.main())  # Exit
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\libzxbc\", line 246, in main
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\arch\zx48k\", line 1401, in start
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\ast\", line 35, in visit
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\arch\zx48k\", line 196, in visit_ARGLIST
    upper = node.parent.entry.bounds[i].upper
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\symbols\", line 29, in __getitem__
    return self.children[key]
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\ast\", line 40, in __getitem__
    return self._children[key]
IndexError: list index out of range

I imaging the problem is that the compiler can't work out the array bounds within the function, unless I tell it. Anyone know if I can modify the source, so array-bound checking will still work?

Thanks in advance,

This crash is a bug. The compiler should never crash (if there's an error in your code it should report the syntax/semantic error and exit gracefully).

I've been able to reproduce it.
Will fix it and let you know.

Messages In This Thread
RE: Using --debug-array with arrays passed to functions - by boriel - 03-10-2021, 10:20 PM

Forum Jump:

Users browsing this thread: 2 Guest(s)