// An ArgumentError holds an error associated with an argument index.
type ArgumentError struct {
- index int
- error
+ Index int
+ Err error
}
-// Index returns the positional index of the argument associated with the
-// error.
-func (e ArgumentError) Index() int {
- return e.index
-}
+func (e *ArgumentError) Error() string { return e.Err.Error() }
+func (e *ArgumentError) Unwrap() error { return e.Err }
// An Importer resolves import paths to Packages.
//
import (
"bytes"
+ "errors"
"fmt"
"go/ast"
"go/importer"
t.Fatalf("Instantiate(%v, %v) returned nil error, want non-nil", T, test.targs)
}
- gotAt := err.(ArgumentError).Index()
- if gotAt != test.wantAt {
- t.Errorf("Instantate(%v, %v): error at index %d, want index %d", T, test.targs, gotAt, test.wantAt)
+ var argErr *ArgumentError
+ if !errors.As(err, &argErr) {
+ t.Fatalf("Instantiate(%v, %v): error is not an *ArgumentError", T, test.targs)
+ }
+
+ if argErr.Index != test.wantAt {
+ t.Errorf("Instantate(%v, %v): error at index %d, want index %d", T, test.targs, argErr.Index, test.wantAt)
}
}
}
// unimplemented.
//
// If verify is set and constraint satisfaction fails, the returned error may
-// be of dynamic type ArgumentError indicating which type argument did not
-// satisfy its corresponding type parameter constraint, and why.
+// wrap an *ArgumentError indicating which type argument did not satisfy its
+// corresponding type parameter constraint, and why.
//
// TODO(rfindley): change this function to also return an error if lengths of
// tparams and targs do not match.
tparams = t.TypeParams().list()
}
if i, err := (*Checker)(nil).verify(token.NoPos, tparams, targs); err != nil {
- return inst, ArgumentError{i, err}
+ return inst, &ArgumentError{i, err}
}
}