Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flag: panic if a flag is defined after being set
As part of developing #57411, we ran into cases where a flag was defined in one package init and Set in another package init, and there was no init ordering implied by the spec between those two packages. Changes in initialization ordering as part of #57411 caused a Set to happen before the definition, which makes the Set silently fail. This CL makes the Set fail loudly in that situation. Currently Set *does* fail kinda quietly in that situation, in that it returns an error. (It seems that no one checks the error from Set, at least for string flags.) Ian suggsted that instead we panic at the definition site if there was previously a Set called on that (at the time undefined) flag. So Set on an undefined flag is ok and returns an error (as before), but defining a flag which has already been Set causes a panic. (The API for flag definition has no way to return an error, and does already panic in some situations like a duplicate definition.) Update #57411 Change-Id: I39b5a49006f9469de0b7f3fe092afe3a352e4fcb Reviewed-on: https://go-review.googlesource.com/c/go/+/480215 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
- Loading branch information