Skip to content

Commit 5868c39

Browse files
committed
Fix parser crash when assigning substr
When assiging a substr to an array string the parser might crash if the array is not declared previously.
1 parent 6dc8093 commit 5868c39

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tests/functional/substr_err.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IF k$<>s$ THEN REM
2+
IF m$(s(1),s(2))="\b" THEN LET m$(s(1),s(2))="\c"

zxbparser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,10 +1166,17 @@ def p_substr_assignment(p):
11661166
if entry.class_ == CLASS.unknown:
11671167
entry.class_ = CLASS.var
11681168

1169-
assert entry.class_ == CLASS.var and entry.type_ == TYPE.string
1169+
if entry.class_ != CLASS.var:
1170+
api.errmsg.syntax_error_cannot_assign_not_a_var(p.lineno(2), p[2])
1171+
return
1172+
1173+
if entry.type_ != TYPE.string:
1174+
api.errmsg.syntax_error_expected_string(p.lineno(2), entry.type_)
1175+
return
11701176

11711177
if p[5].type_ != TYPE.string:
11721178
api.errmsg.syntax_error_expected_string(p.lineno(4), p[5].type_)
1179+
return
11731180

11741181
if len(p[3]) > 1:
11751182
syntax_error(p.lineno(2), "Accessing string with too many indexes. Expected only one.")

0 commit comments

Comments
 (0)