-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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/stdmethods: add tests with generic receivers
Ensure that the logic for detecting incorrect signatures of standard methods applies to methods on generic types. For golang/go#48704 Change-Id: I1862238ad1ff013137b12674fbc0068a7e8a3c60 Reviewed-on: https://go-review.googlesource.com/c/tools/+/359409 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tim King <taking@google.com>
- Loading branch information
Showing
2 changed files
with
47 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
41 changes: 41 additions & 0 deletions
41
go/analysis/passes/stdmethods/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,41 @@ | ||
// 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. | ||
|
||
package typeparams | ||
|
||
import "fmt" | ||
|
||
type T[P any] int | ||
|
||
func (T[_]) Scan(x fmt.ScanState, c byte) {} // want `should have signature Scan\(fmt\.ScanState, rune\) error` | ||
|
||
func (T[_]) Format(fmt.State, byte) {} // want `should have signature Format\(fmt.State, rune\)` | ||
|
||
type U[P any] int | ||
|
||
func (U[_]) Format(byte) {} // no error: first parameter must be fmt.State to trigger check | ||
|
||
func (U[P]) GobDecode(P) {} // want `should have signature GobDecode\(\[\]byte\) error` | ||
|
||
type V[P any] int // V does not implement error. | ||
|
||
func (V[_]) As() T[int] { return 0 } // ok - V is not an error | ||
func (V[_]) Is() bool { return false } // ok - V is not an error | ||
func (V[_]) Unwrap() int { return 0 } // ok - V is not an error | ||
|
||
type E[P any] int | ||
|
||
func (E[_]) Error() string { return "" } // E implements error. | ||
|
||
func (E[P]) As() {} // want `method As\(\) should have signature As\(interface{}\) bool` | ||
func (E[_]) Is() {} // want `method Is\(\) should have signature Is\(error\) bool` | ||
func (E[_]) Unwrap() {} // want `method Unwrap\(\) should have signature Unwrap\(\) error` | ||
|
||
type F[P any] int | ||
|
||
func (F[_]) Error() string { return "" } // Both F and *F implement error. | ||
|
||
func (*F[_]) As() {} // want `method As\(\) should have signature As\(interface{}\) bool` | ||
func (*F[_]) Is() {} // want `method Is\(\) should have signature Is\(error\) bool` | ||
func (*F[_]) Unwrap() {} // want `method Unwrap\(\) should have signature Unwrap\(\) error` |