From 66294e359a8d1289ac2e0accadaa5d089e92ddf7 Mon Sep 17 00:00:00 2001 From: Enzo Date: Tue, 13 Apr 2021 05:55:41 +0200 Subject: [PATCH] checker: add immutable_builtin_modify.vv test (#9702) --- vlib/v/checker/checker.v | 4 +--- vlib/v/checker/tests/immutable_builtin_modify.out | 11 +++++++++++ vlib/v/checker/tests/immutable_builtin_modify.vv | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 vlib/v/checker/tests/immutable_builtin_modify.out create mode 100644 vlib/v/checker/tests/immutable_builtin_modify.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4b915da5d2..15c616868a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) } } diff --git a/vlib/v/checker/tests/immutable_builtin_modify.out b/vlib/v/checker/tests/immutable_builtin_modify.out new file mode 100644 index 0000000000..059e3bc5ae --- /dev/null +++ b/vlib/v/checker/tests/immutable_builtin_modify.out @@ -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 + | ~~~ diff --git a/vlib/v/checker/tests/immutable_builtin_modify.vv b/vlib/v/checker/tests/immutable_builtin_modify.vv new file mode 100644 index 0000000000..e6cb7060b8 --- /dev/null +++ b/vlib/v/checker/tests/immutable_builtin_modify.vv @@ -0,0 +1,5 @@ +s := '' +s.len = 123 +// +b := []byte{} +b.len = 34