-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)FrozenDueToAgeProposalProposal-AcceptedProposal-FinalCommentPeriod
Milestone
Description
What version of Go are you using (go version
)?
$ go version go version go1.16.6 darwin/arm64
Does this issue reproduce with the latest release?
yes
What did you do?
Wrote this code https://play.golang.org/p/16cU0kc8Lku and wondered why the errors matched.
var Err = errors.New("sentinel")
err := errors.New("foo")
if errors.As(err, &Err) {
fmt.Println("why?")
}
Discussion in https://groups.google.com/g/golang-nuts/c/MaYJy_IRbYA/m/uCHV6P87EQAJ?utm_medium=email&utm_source=footer
What did you expect to see?
Of course the code above is wrong, yet I didn't spot it. It would be nice if this kind of programming error could be detected:
- add a
govet
check that flags using plainerror
s witherrors.As
or - @Merovius suggested
errors.errorString
should implementAs()
and returnfalse
, unless the pointers match.
I'm unsure if the latter is possible. It would strictly break BC (and the function's description). On the other hand ist should only change behaviour in cases that seem invalid from the start?
ainar-g, syumai, marco-m-pix4d and yogihardi
Metadata
Metadata
Assignees
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)FrozenDueToAgeProposalProposal-AcceptedProposal-FinalCommentPeriod