Skip to content

Commit cc6eaa8

Browse files
authored
Merge pull request #582 from boriel/bugfix/crash_on_string_index
fix: fixes crash on bad array index
2 parents fe50d5b + 64e213a commit cc6eaa8

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/zxbc/zxbparser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ def make_array_access(id_, lineno, arglist):
323323
This is an RVALUE (Read the element)
324324
"""
325325
for i, arg in enumerate(arglist):
326-
arg.value = make_typecast(TYPE.by_name(src.api.constants.TYPE.to_string(gl.BOUND_TYPE)), arg.value, arg.lineno)
326+
value = make_typecast(TYPE.by_name(src.api.constants.TYPE.to_string(gl.BOUND_TYPE)), arg.value, arg.lineno)
327+
if value is None: # semantic error?
328+
return None # return error
329+
arg.value = value
327330

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

tests/functional/test_errmsg.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ dim_str_error0.bas:3: error: Cannot initialize array of type string
206206
>>> process_file('zx48k/dim_str_error1.bas')
207207
dim_str_error1.bas:3: error: Cannot initialize array of type string
208208

209+
>>> process_file('zx48k/sn_crash.bas')
210+
sn_crash.bas:4: error: Cannot convert string to a value. Use VAL() function
211+
209212
# Test parsing error improvements
210213
>>> process_file('zx48k/for_err.bas')
211214
for_err.bas:3: error: FOR without NEXT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DIM p(10) AS Ubyte
2+
DIM f as String
3+
4+
LET p(f) = 0

0 commit comments

Comments
 (0)