-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document named return constraint for defer (#63)
As discussed in #61, if you attempt to use defer multierr.AppendInvoke with an error that is not a named return, the system will lose the error. func fails() error { return errors.New("great sadness") } func foo() error { var err error defer multierr.AppendInvoke(&err, multierr.Invoke(fails)) return err } func main() { fmt.Println(foo()) // nil } https://go.dev/play/p/qK4NR-VYLvo This isn't something the library can address because of how defers work. This change adds a warning about the error variable being a named return in all places where we suggest use of multierr with defer. While we're at it, this makes use of the new [Foo] godoc syntax to generate links to other functions in the package in "See Foo" statements in the documentation.
- Loading branch information
Showing
1 changed file
with
18 additions
and
4 deletions.
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