Skip to content

Commit

Permalink
Fix invalid array index causing assertion.
Browse files Browse the repository at this point in the history
Bug: issue #895
Test: new test case
  • Loading branch information
dvander committed Nov 29, 2023
1 parent 5f87e3c commit c96fab0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,8 @@ bool Semantics::CheckIndexExpr(IndexExpr* expr) {
report(base, 29);
return false;
}
if (base_val.sym->ident() != iARRAY && base_val.sym->ident() != iREFARRAY) {
report(base, 28) << base_val.sym->name();
if (base_val.ident != iARRAY && base_val.ident != iREFARRAY) {
report(index, 28) << base_val.sym->name();
return false;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/compile-only/fail-array-extra-indices.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum struct A
{
int b[1];
}

public void main()
{
A a;
a.b[0] = 0;
a.b[0][0] = 0;
a.b[0][0][0] = 0;
a.b[0][0][0][0] = 0;
}
3 changes: 3 additions & 0 deletions tests/compile-only/fail-array-extra-indices.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(10) : error 028: invalid subscript (not an array or too many subscripts): "b"
(11) : error 028: invalid subscript (not an array or too many subscripts): "b"
(12) : error 028: invalid subscript (not an array or too many subscripts): "b"

0 comments on commit c96fab0

Please sign in to comment.