2019-08-30 19:19:06 +02:00
|
|
|
/* 1 */ struct A { mut: v int }
|
|
|
|
/* 2 */ struct B { a A }
|
|
|
|
/* 3 */ struct C { mut: b B }
|
|
|
|
/* 4 */ struct D { mut: c C }
|
|
|
|
|
|
|
|
/* 5 */ struct E { mut: v []int }
|
|
|
|
/* 6 */ struct F { e []E }
|
|
|
|
|
|
|
|
/* 7 */ mut s := 'hello world'
|
|
|
|
/*( 8)*/ s.len = 0 // Error (field len immutable)
|
|
|
|
|
|
|
|
/* 8 */ mut b := B{}
|
|
|
|
/*( 9)*/ b.a.v = 1 // Error (field a immutable)
|
|
|
|
/*( 9)*/ b.a = A{} // Error (field a immutable)
|
|
|
|
/* 9 */ b = B{A{2}} // Correct
|
|
|
|
|
|
|
|
/* 10 */ mut c := C{}
|
|
|
|
/* 11 */ c.b = B{} // Correct
|
|
|
|
/*(12)*/ c.b.a = A{} // Error (field a immutable)
|
|
|
|
/*(12)*/ c.b.a.v = 1 // Error (field a immutable)
|
|
|
|
|
|
|
|
/* 12 */ c2 := C{}
|
|
|
|
/*(13)*/ c2.b = B{} // Error (c2 immutable)
|
|
|
|
/* 13 */ mut d := D{}
|
|
|
|
/* 14 */ d.c.b = B{} // Correct
|
|
|
|
|
|
|
|
/* 15 */ mut f := F{}
|
|
|
|
/*(16)*/ f.e << E{} // Error (field e immutable)
|
|
|
|
/*(16)*/ f.e[0].v << 1 // Error (field e immutable)
|
|
|
|
|
|
|
|
/* 16 */ e := E{}
|
|
|
|
/*(17)*/ e.v << 1 // Error (e immutable)
|
|
|
|
|
|
|
|
===output===
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:27:14: cannot modify immutable field `len` (type `string`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct string {
|
|
|
|
mut:
|
|
|
|
len int
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:30:14: cannot modify immutable field `a` (type `B`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct B {
|
|
|
|
mut:
|
|
|
|
a A
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:29:12: cannot modify immutable field `a` (type `B`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct B {
|
|
|
|
mut:
|
|
|
|
a A
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:41:14: cannot modify immutable field `a` (type `B`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct B {
|
|
|
|
mut:
|
|
|
|
a A
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:42:16: cannot modify immutable field `a` (type `B`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct B {
|
|
|
|
mut:
|
|
|
|
a A
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:44:15: `c2` is immutable
|
|
|
|
.vrepl_temp.v:53:12: cannot modify immutable field `e` (type `F`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct F {
|
|
|
|
mut:
|
|
|
|
e []E
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:54:17: cannot modify immutable field `e` (type `F`)
|
2019-08-30 19:19:06 +02:00
|
|
|
declare the field with `mut:`
|
|
|
|
struct F {
|
|
|
|
mut:
|
|
|
|
e []E
|
|
|
|
}
|
2019-10-06 16:21:10 +02:00
|
|
|
.vrepl_temp.v:57:17: `e` is immutable (can't <<)
|