-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/deepequalerrors: add typeparams test
This CL adds a test for the assign pass that involves use of generics. Update golang/go#48704 Change-Id: I1aa51aed24d63d42b6b0150d64925b97dfd59a92 Reviewed-on: https://go-review.googlesource.com/c/tools/+/357412 Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Trust: Cherry Mui <cherryyz@google.com>
- Loading branch information
1 parent
9b675d0
commit 4100dac
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
go/analysis/passes/deepequalerrors/testdata/src/typeparams/typeparams.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2021 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. | ||
|
||
// This file contains tests for the deepequalerrors checker. | ||
|
||
package a | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"reflect" | ||
) | ||
|
||
type myError int | ||
|
||
func (myError) Error() string { return "" } | ||
|
||
func bad[T any]() T { | ||
var t T | ||
return t | ||
} | ||
|
||
type s1 struct { | ||
s2 *s2[myError2] | ||
i int | ||
} | ||
|
||
type myError2 error | ||
|
||
type s2[T any] struct { | ||
s1 *s1 | ||
errs []*T | ||
} | ||
|
||
func hasError() { | ||
var e error | ||
var m myError2 | ||
reflect.DeepEqual(bad[error](), e) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(io.EOF, io.EOF) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(e, &e) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(e, m) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(e, s1{}) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(e, [1]error{}) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(e, map[error]int{}) // want `avoid using reflect.DeepEqual with errors` | ||
reflect.DeepEqual(e, map[int]error{}) // want `avoid using reflect.DeepEqual with errors` | ||
// We catch the next not because *os.PathError implements error, but because it contains | ||
// a field Err of type error. | ||
reflect.DeepEqual(&os.PathError{}, io.EOF) // want `avoid using reflect.DeepEqual with errors` | ||
|
||
} | ||
|
||
func notHasError() { | ||
reflect.ValueOf(4) // not reflect.DeepEqual | ||
reflect.DeepEqual(3, 4) // not errors | ||
reflect.DeepEqual(5, io.EOF) // only one error | ||
reflect.DeepEqual(myError(1), io.EOF) // not types that implement error | ||
} |