1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:14:41 -07:00

cmd/compile: better error msg for impossible type assertions

Revise the error message under the condition that type assertion has
mismatching pointer/non-pointer type, which means this PR adds a
better error hint for the situation that a user writes x.(*I), but they
meant to write x.(I).

In this situation, compiler would check out whether the the missing
methods are implemented by the dereferenced object. If the dereferenced
object implements these missing methods, then return error message
`<original_object> does not have <missing_method> (but
<dereferenced_object> does)`

Fixes #43673
This commit is contained in:
HowJMay 2021-01-22 01:12:51 +08:00
parent 189c6946f5
commit 530585b713
2 changed files with 4045 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
// errorcheck
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 43673
package main
type I interface {
M()
}
type T struct{}
func (t *T) M() {}
func main() {
var i I
_ = i.(*I) // ERROR "*I does not implement I (but I does)"
}