diff --git a/guppylang/checker/stmt_checker.py b/guppylang/checker/stmt_checker.py index 68269f80..047eb180 100644 --- a/guppylang/checker/stmt_checker.py +++ b/guppylang/checker/stmt_checker.py @@ -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 diff --git a/tests/error/array_errors/mutate.err b/tests/error/array_errors/mutate.err new file mode 100644 index 00000000..615f5c5d --- /dev/null +++ b/tests/error/array_errors/mutate.err @@ -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 diff --git a/tests/error/array_errors/mutate.py b/tests/error/array_errors/mutate.py new file mode 100644 index 00000000..98140e4e --- /dev/null +++ b/tests/error/array_errors/mutate.py @@ -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()