Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#582 from boriel/bugfix/crash_on_strin…
Browse files Browse the repository at this point in the history
…g_index

fix: fixes crash on bad array index
  • Loading branch information
boriel committed Nov 7, 2021
2 parents fe50d5b + 64e213a commit cc6eaa8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/zxbc/zxbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ def make_array_access(id_, lineno, arglist):
This is an RVALUE (Read the element)
"""
for i, arg in enumerate(arglist):
arg.value = make_typecast(TYPE.by_name(src.api.constants.TYPE.to_string(gl.BOUND_TYPE)), arg.value, arg.lineno)
value = make_typecast(TYPE.by_name(src.api.constants.TYPE.to_string(gl.BOUND_TYPE)), arg.value, arg.lineno)
if value is None: # semantic error?
return None # return error
arg.value = value

return symbols.ARRAYACCESS.make_node(id_, arglist, lineno, gl.FILENAME)

Expand Down
3 changes: 3 additions & 0 deletions tests/functional/test_errmsg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ dim_str_error0.bas:3: error: Cannot initialize array of type string
>>> process_file('zx48k/dim_str_error1.bas')
dim_str_error1.bas:3: error: Cannot initialize array of type string

>>> process_file('zx48k/sn_crash.bas')
sn_crash.bas:4: error: Cannot convert string to a value. Use VAL() function

# Test parsing error improvements
>>> process_file('zx48k/for_err.bas')
for_err.bas:3: error: FOR without NEXT
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/zx48k/sn_crash.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DIM p(10) AS Ubyte
DIM f as String

LET p(f) = 0

0 comments on commit cc6eaa8

Please sign in to comment.