Commit 92fdfda
committed
go/analysis/passes/modernize: errorsastype: errors.As -> AsType[T]
This CL adds a modernizer that replaces simple uses of
errors.As such as:
var myerr *MyErr
if errors.As(err, &myerr) {
handle(myerr)
}
with the less error-prone generic [errors.AsType] function,
introduced in Go 1.26:
if myerr, ok := errors.AsType[*MyErr](err); ok {
handle(myerr)
}
Also, redo the existing errorsas vet check (for actual bugs)
to take advantage of newer analysis features.
Fixes golang/go#75692
Updates golang/go#51945
Change-Id: I56bd5370449daeacedf5634e46c2a29697dcbf19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/708895
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>1 parent 133beb8 commit 92fdfda
File tree
14 files changed
+477
-39
lines changed- gopls
- doc
- internal
- doc
- settings
- go/analysis/passes
- errorsas
- modernize
- testdata/src/errorsastype
- dotimport
- internal/goplsexport
14 files changed
+477
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 15 | + | |
| 16 | + | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
| 21 | + | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
| |||
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
47 | 44 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 45 | + | |
| 46 | + | |
57 | 47 | | |
58 | | - | |
| 48 | + | |
59 | 49 | | |
60 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
61 | 53 | | |
| 54 | + | |
62 | 55 | | |
63 | | - | |
| 56 | + | |
64 | 57 | | |
65 | 58 | | |
66 | 59 | | |
67 | | - | |
68 | | - | |
69 | 60 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
74 | 65 | | |
75 | 66 | | |
76 | 67 | | |
77 | 68 | | |
78 | 69 | | |
79 | 70 | | |
80 | 71 | | |
81 | | - | |
| 72 | + | |
82 | 73 | | |
83 | 74 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 75 | + | |
| 76 | + | |
87 | 77 | | |
88 | | - | |
| 78 | + | |
89 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
92 | 114 | | |
93 | 115 | | |
94 | 116 | | |
| |||
0 commit comments