From 712f3df8842f48f988cebfc527476781a7cf7140 Mon Sep 17 00:00:00 2001 From: Pantelis Sampaziotis Date: Tue, 10 Sep 2019 14:21:07 +0300 Subject: [PATCH] Add Unwrap to NumError --- src/strconv/atoi.go | 2 ++ src/strconv/atoi_test.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/strconv/atoi.go b/src/strconv/atoi.go index 131b088e31b..a4a8a37fb42 100644 --- a/src/strconv/atoi.go +++ b/src/strconv/atoi.go @@ -31,6 +31,8 @@ func (e *NumError) Error() string { return "strconv." + e.Func + ": " + "parsing " + Quote(e.Num) + ": " + e.Err.Error() } +func (e *NumError) Unwrap() error { return e.Err } + func syntaxError(fn, str string) *NumError { return &NumError{fn, str, ErrSyntax} } diff --git a/src/strconv/atoi_test.go b/src/strconv/atoi_test.go index b167c96833c..178fb01ea7e 100644 --- a/src/strconv/atoi_test.go +++ b/src/strconv/atoi_test.go @@ -592,6 +592,13 @@ func TestNumError(t *testing.T) { } } +func TestNumErrorUnwrap(t *testing.T) { + err := &NumError{Err: ErrSyntax} + if !errors.Is(err, ErrSyntax) { + t.Error("errors.Is failed, wanted success") + } +} + func BenchmarkParseInt(b *testing.B) { b.Run("Pos", func(b *testing.B) { benchmarkParseInt(b, 1)