Skip to content

Commit

Permalink
Merge pull request #1118 from CityOfZion/CU-2ewej29
Browse files Browse the repository at this point in the history
Add an error when using the list slice assignment
  • Loading branch information
melanke committed Aug 17, 2023
2 parents 084f801 + 1177283 commit 3bd6bed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions boa3/internal/analyser/moduleanalyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,11 @@ def visit_Assign(self, assign: ast.Assign):
CompilerError.NotSupportedOperation(assign.lineno, assign.col_offset, 'Multiple variable assignments')
)

elif isinstance(assign.targets[0], ast.Subscript) and isinstance(assign.targets[0].slice, ast.Slice):
self._log_error(
CompilerError.NotSupportedOperation(assign.lineno, assign.col_offset, 'Assigning a value into a slice')
)

else:
var_type = self.visit_type(assign.value)

Expand Down
10 changes: 10 additions & 0 deletions boa3_test/test_sc/list_test/SetListIntoListSlice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import List

from boa3.builtin.compile_time import public


@public
def main() -> List[int]:
a = [1, 2, 3, 4, 5, 6]
a[:3] = [10]
return a
4 changes: 4 additions & 0 deletions boa3_test/tests/compiler_tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ def test_list_assign_empty_list(self):
output = self.compile(path)
self.assertEqual(expected_output, output)

def test_list_set_into_list_slice(self):
path = self.get_contract_path('SetListIntoListSlice.py')
self.assertCompilerLogs(CompilerError.NotSupportedOperation, path)

def test_list_set_value(self):
path = self.get_contract_path('SetValue.py')
self.assertCompilerNotLogs(CompilerWarning.NameShadowing, path)
Expand Down

0 comments on commit 3bd6bed

Please sign in to comment.