3 // Copyright 2020 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test "cannot assign" errors
12 var s string = "hello"
13 s[1:2] = "a" // ERROR "cannot assign to .* (\(strings are immutable\))?"
14 s[3] = "b" // ERROR "cannot assign to .* (\(strings are immutable\))?"
17 const cs string = "hello"
18 n = 2 // ERROR "cannot assign to .* (\(declared const\))?"
19 cs = "hi" // ERROR "cannot assign to .* (\(declared const\))?"
20 true = false // ERROR "cannot assign to .* (\(declared const\))?"
22 var m map[int]struct{ n int }
23 m[0].n = 7 // ERROR "cannot assign to struct field .* in map$"
25 1 = 7 // ERROR "cannot assign to 1"
26 "hi" = 7 // ERROR `cannot assign to "hi"`
27 nil = 7 // ERROR "cannot assign to nil"
28 len("") = 7 // ERROR `cannot assign to len\(""\)`
29 []int{} = nil // ERROR "cannot assign to \[\]int\{\}"
32 x + 1 = 7 // ERROR "cannot assign to x \+ 1"