Skip to content

Commit

Permalink
fix: Properly report errors for unsupported subscript assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch committed Dec 20, 2024
1 parent db86f98 commit 23a2f2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions guppylang/checker/stmt_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def _check_field_assign(
place = FieldAccess(value.place, struct_ty.field_dict[attr], lhs)
return with_loc(lhs, with_type(rhs_ty, PlaceNode(place=place)))

@_check_assign.register
def _check_subscript_assign(
self, lhs: ast.Subscript, rhs: ast.expr, rhs_ty: Type
) -> AnyUnpack:
raise GuppyError(UnsupportedError(lhs, "Subscript assignments"))

@_check_assign.register
def _check_tuple_assign(
self, lhs: ast.Tuple, rhs: ast.expr, rhs_ty: Type
Expand Down
8 changes: 8 additions & 0 deletions tests/error/array_errors/mutate.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Error: Unsupported (at $FILE:11:4)
|
9 | @guppy(module)
10 | def main(xs: array[int, 10]) -> None:
11 | xs[0] = 1
| ^^^^^ Subscript assignments are not supported

Guppy compilation failed due to 1 previous error
14 changes: 14 additions & 0 deletions tests/error/array_errors/mutate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.std.builtins import array, owned


module = GuppyModule("test")


@guppy(module)
def main(xs: array[int, 10]) -> None:
xs[0] = 1


module.compile()

0 comments on commit 23a2f2e

Please sign in to comment.