v/compiler/tests/repl/immutable_len_fields.repl

31 lines
627 B
Plaintext
Raw Normal View History

mut s := 'hello world'
s.len = 0 // Error (field len immutable)
mut a := []string
a.len = 0 // Error (field len immutable)
mut ints := []int
ints.len = 0 // Error (field len immutable)
println('BYE')
===output===
.vrepl_temp.v:2:5: cannot modify immutable field `len` (type `string`)
declare the field with `mut:`
struct string {
mut:
len int
}
.vrepl_temp.v:3:5: cannot modify immutable field `len` (type `array`)
declare the field with `mut:`
struct array {
mut:
len int
}
.vrepl_temp.v:4:8: cannot modify immutable field `len` (type `array`)
declare the field with `mut:`
struct array {
mut:
len int
}
BYE