xerrors: require that error be type assertable to As's target

Document As(err, target) as panicking when *target is not of interface
type and does not implement the error interface. While this prevents
some clever tricks, it permits catching (at runtime or statically
via vet) type errors equivalent to the ones that can be detected
by type assertions.

  if e := os.PathError{}; errors.As(err, &e) {  // error, os.PathError does not implement error
  if e := &os.PathError{}; errors.As(err, e) {  // error, os.PathError does not implement error
  if e := &os.PathError{}; errors.As(err, &e) { // ok

  var e interface{ Timeout() bool }
  if errors.As(&e) && e.Timeout() { // ok

Change-Id: I3607ac62fbe8aebef3c1aeec3fb414fb41afcdda
Reviewed-on: https://go-review.googlesource.com/c/161899
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2 files changed