checker: add an error for assigning to array slices `a[..2] = [0, 0]` (#10412)
							parent
							
								
									5be982d63e
								
							
						
					
					
						commit
						10b9ea3258
					
				|  | @ -3268,6 +3268,11 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) { | |||
| 		if left is ast.CallExpr { | ||||
| 			c.error('cannot call function `${left.name}()` on the left side of an assignment', | ||||
| 				left.pos) | ||||
| 		} else if left is ast.IndexExpr { | ||||
| 			if left.index is ast.RangeExpr { | ||||
| 				c.error('cannot reassign using range expression on the left side of an assignment', | ||||
| 					left.pos) | ||||
| 			} | ||||
| 		} | ||||
| 		is_blank_ident := left.is_blank_ident() | ||||
| 		mut left_type := ast.void_type | ||||
|  |  | |||
|  | @ -0,0 +1,7 @@ | |||
| vlib/v/checker/tests/slice_reassignment.vv:3:5: error: cannot reassign using range expression on the left side of an assignment | ||||
|     1 | fn main() { | ||||
|     2 |     mut arr := [1, 2, 3, 4, 5] | ||||
|     3 |     arr[..2] = [0, 0] | ||||
|       |        ~~~~~ | ||||
|     4 |     println(arr) | ||||
|     5 | } | ||||
|  | @ -0,0 +1,5 @@ | |||
| fn main() { | ||||
| 	mut arr := [1, 2, 3, 4, 5] | ||||
| 	arr[..2] = [0, 0] | ||||
| 	println(arr) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue