mirror of
https://github.com/golang/go
synced 2024-11-18 08:54:45 -07:00
internal/lsp/analysis/fillreturns: broaden type equality
The existing implementation contains strict equality rules for comparing the return type in the function declaration against the return types in the function body. This causes the code in the return statement to be incorrectly overriden with its corresponding zero value type by the fillreturns analyzer. Fixes golang/go#38707 Change-Id: I07522aaf85f2a5f811a86cbc0951ae61035ff55e Reviewed-on: https://go-review.googlesource.com/c/tools/+/236617 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
1679474780
commit
cef9fc3bc8
@ -186,8 +186,7 @@ func equalTypes(t1, t2 types.Type) bool {
|
||||
return rhs.Info()&types.IsConstType == lhs.Info()&types.IsConstType
|
||||
}
|
||||
}
|
||||
// TODO: Figure out if we want to check for types.AssignableTo(t1, t2) || types.ConvertibleTo(t1, t2)
|
||||
return false
|
||||
return types.AssignableTo(t1, t2) || types.ConvertibleTo(t1, t2)
|
||||
}
|
||||
|
||||
func FixesError(msg string) bool {
|
||||
|
@ -68,3 +68,13 @@ func m() (int, error) {
|
||||
}
|
||||
return // want "wrong number of return values \\(want 2, got 0\\)"
|
||||
}
|
||||
|
||||
func convertibleTypes() (ast2.Expr, int) {
|
||||
return &ast2.ArrayType{} // want "wrong number of return values \\(want 2, got 1\\)"
|
||||
}
|
||||
|
||||
func assignableTypes() (map[string]int, int) {
|
||||
type X map[string]int
|
||||
var x X
|
||||
return x // want "wrong number of return values \\(want 2, got 1\\)"
|
||||
}
|
||||
|
@ -68,3 +68,13 @@ func m() (int, error) {
|
||||
}
|
||||
return 0, nil // want "wrong number of return values \\(want 2, got 0\\)"
|
||||
}
|
||||
|
||||
func convertibleTypes() (ast2.Expr, int) {
|
||||
return &ast2.ArrayType{}, 0 // want "wrong number of return values \\(want 2, got 1\\)"
|
||||
}
|
||||
|
||||
func assignableTypes() (map[string]int, int) {
|
||||
type X map[string]int
|
||||
var x X
|
||||
return x, 0 // want "wrong number of return values \\(want 2, got 1\\)"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user