File tree 2 files changed +47
-1
lines changed
go/analysis/passes/stdmethods
2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,16 @@ import (
9
9
10
10
"golang.org/x/tools/go/analysis/analysistest"
11
11
"golang.org/x/tools/go/analysis/passes/stdmethods"
12
+ "golang.org/x/tools/internal/typeparams"
12
13
)
13
14
14
15
func Test (t * testing.T ) {
15
16
testdata := analysistest .TestData ()
16
- analysistest .Run (t , testdata , stdmethods .Analyzer , "a" )
17
+ pkgs := []string {"a" }
18
+ if typeparams .Enabled {
19
+ pkgs = append (pkgs , "typeparams" )
20
+ }
21
+ analysistest .Run (t , testdata , stdmethods .Analyzer , pkgs ... )
17
22
}
18
23
19
24
func TestAnalyzeEncodingXML (t * testing.T ) {
Original file line number Diff line number Diff line change
1
+ // Copyright 2021 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package typeparams
6
+
7
+ import "fmt"
8
+
9
+ type T [P any ] int
10
+
11
+ func (T [_ ]) Scan (x fmt.ScanState , c byte ) {} // want `should have signature Scan\(fmt\.ScanState, rune\) error`
12
+
13
+ func (T [_ ]) Format (fmt.State , byte ) {} // want `should have signature Format\(fmt.State, rune\)`
14
+
15
+ type U [P any ] int
16
+
17
+ func (U [_ ]) Format (byte ) {} // no error: first parameter must be fmt.State to trigger check
18
+
19
+ func (U [P ]) GobDecode (P ) {} // want `should have signature GobDecode\(\[\]byte\) error`
20
+
21
+ type V [P any ] int // V does not implement error.
22
+
23
+ func (V [_ ]) As () T [int ] { return 0 } // ok - V is not an error
24
+ func (V [_ ]) Is () bool { return false } // ok - V is not an error
25
+ func (V [_ ]) Unwrap () int { return 0 } // ok - V is not an error
26
+
27
+ type E [P any ] int
28
+
29
+ func (E [_ ]) Error () string { return "" } // E implements error.
30
+
31
+ func (E [P ]) As () {} // want `method As\(\) should have signature As\(interface{}\) bool`
32
+ func (E [_ ]) Is () {} // want `method Is\(\) should have signature Is\(error\) bool`
33
+ func (E [_ ]) Unwrap () {} // want `method Unwrap\(\) should have signature Unwrap\(\) error`
34
+
35
+ type F [P any ] int
36
+
37
+ func (F [_ ]) Error () string { return "" } // Both F and *F implement error.
38
+
39
+ func (* F [_ ]) As () {} // want `method As\(\) should have signature As\(interface{}\) bool`
40
+ func (* F [_ ]) Is () {} // want `method Is\(\) should have signature Is\(error\) bool`
41
+ func (* F [_ ]) Unwrap () {} // want `method Unwrap\(\) should have signature Unwrap\(\) error`
You can’t perform that action at this time.
0 commit comments