| 1 | // Copyright 2026 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 errorsastypeshadow checks for shadowing problems when |
| 6 | // [errors.AsType] is used in an if/else chain. |
| 7 | // |
| 8 | // # Analyzer errorsastypeshadow |
| 9 | // |
| 10 | // errorsastypeshadow: report shadowing of errors.AsType[T] in if/else chains |
| 11 | // |
| 12 | // For example: |
| 13 | // |
| 14 | // err := f() |
| 15 | // if err, ok := errors.AsType[*FooErr](err); ok { |
| 16 | // useFoo(err) |
| 17 | // } else if err, ok := errors.AsType[*BarErr](err); ok { |
| 18 | // useBar(err) |
| 19 | // } |
| 20 | // |
| 21 | // In this case, the second call to errors.AsType does not operate on the |
| 22 | // original error. Instead, its operand is the zero value of type *FooErr |
| 23 | // produced by the first if statement; this is invariably a mistake. |
| 24 | package errorsastypeshadow |