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:
parent
189c6946f5
commit
530585b713
4024
src/cmd/compile/internal/gc/typecheck.go
Normal file
4024
src/cmd/compile/internal/gc/typecheck.go
Normal file
File diff suppressed because it is too large
Load Diff
21
test/fixedbugs/issue43673.go
Normal file
21
test/fixedbugs/issue43673.go
Normal 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)"
|
||||
}
|
Loading…
Reference in New Issue
Block a user