checker: add immutable_builtin_modify.vv test (#9702)
parent
c3ccb58450
commit
66294e359a
|
@ -1245,9 +1245,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
|
|||
}
|
||||
.array, .string {
|
||||
// This should only happen in `builtin`
|
||||
// TODO Remove `crypto.rand` when possible (see vlib/crypto/rand/rand.v,
|
||||
// if `c_array_to_bytes_tmp` doesn't exist, then it's safe to remove it)
|
||||
if c.file.mod.name !in ['builtin', 'crypto.rand'] {
|
||||
if c.file.mod.name != 'builtin' {
|
||||
c.error('`$typ_sym.kind` can not be modified', expr.pos)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
vlib/v/checker/tests/immutable_builtin_modify.vv:2:3: error: `string` can not be modified
|
||||
1 | s := ''
|
||||
2 | s.len = 123
|
||||
| ~~~
|
||||
3 | //
|
||||
4 | b := []byte{}
|
||||
vlib/v/checker/tests/immutable_builtin_modify.vv:5:3: error: `array` can not be modified
|
||||
3 | //
|
||||
4 | b := []byte{}
|
||||
5 | b.len = 34
|
||||
| ~~~
|
|
@ -0,0 +1,5 @@
|
|||
s := ''
|
||||
s.len = 123
|
||||
//
|
||||
b := []byte{}
|
||||
b.len = 34
|
Loading…
Reference in New Issue