mirror of
https://github.com/golang/go
synced 2024-11-18 11:24:41 -07:00
72ad2f44ea
Added a new flag -G to run. Setting -G (as in: go run run.go -G) will run tests marked with "errorcheck" (and no other flags) also with the compiler using the new typechecker. Many tests don't pass yet (due to discrepancies in error messages). The top-level tests in the test directory which don't pass yet have been explicitly excluded, permitting to see the current status. Future CLs will bring error messages in sync and eventually all tests should pass. Change-Id: I7caf5eff413e173f68d092af4bbe458434718d74 Reviewed-on: https://go-review.googlesource.com/c/go/+/274313 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
// errorcheck
|
|
|
|
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Test "cannot assign" errors
|
|
|
|
package main
|
|
|
|
func main() {
|
|
var s string = "hello"
|
|
s[1:2] = "a" // ERROR "cannot assign to .* (\(strings are immutable\))?"
|
|
s[3] = "b" // ERROR "cannot assign to .* (\(strings are immutable\))?"
|
|
|
|
const n int = 1
|
|
const cs string = "hello"
|
|
n = 2 // ERROR "cannot assign to .* (\(declared const\))?"
|
|
cs = "hi" // ERROR "cannot assign to .* (\(declared const\))?"
|
|
true = false // ERROR "cannot assign to .* (\(declared const\))?"
|
|
|
|
var m map[int]struct{ n int }
|
|
m[0].n = 7 // ERROR "cannot assign to struct field .* in map$"
|
|
|
|
1 = 7 // ERROR "cannot assign to 1"
|
|
"hi" = 7 // ERROR `cannot assign to "hi"`
|
|
nil = 7 // ERROR "cannot assign to nil"
|
|
len("") = 7 // ERROR `cannot assign to len\(""\)`
|
|
[]int{} = nil // ERROR "cannot assign to \[\]int\{\}"
|
|
|
|
var x int = 7
|
|
x + 1 = 7 // ERROR "cannot assign to x \+ 1"
|
|
}
|