mirror of
https://github.com/golang/go
synced 2024-11-22 10:54:46 -07:00
8f19394b62
Based on https://golang.org/cl/284256 for go/types. Brings this code more in line with go/types. Adjusted various tests to match new error messages which generally are now better: for assignment errors, instead of a generic "cannot convert" we now say "cannot use" followed by a clearer reason as to why not. Major differences to go/types with respect to the changed files: - Some of the new code now returns error codes, but they are only used internally for now, and not reported with errors. - go/types does not "convert" untyped nil values to target types, but here we do. This is unchanged from how types2 handled this before this CL. Change-Id: If45336d7ee679ece100f6d9d9f291a6ea55004d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/302757 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
19 lines
509 B
Go
19 lines
509 B
Go
// errorcheck
|
|
|
|
// Copyright 2009 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.
|
|
|
|
package main
|
|
|
|
var t []int
|
|
var s string;
|
|
var m map[string]int;
|
|
|
|
func main() {
|
|
println(t["hi"]); // ERROR "non-integer slice index|must be integer|cannot convert"
|
|
println(s["hi"]); // ERROR "non-integer string index|must be integer|cannot convert"
|
|
println(m[0]); // ERROR "cannot use.*as type string|cannot convert|cannot use"
|
|
}
|
|
|