mirror of https://github.com/golang/go.git
internal/lsp: prioritize non-"zero" values in fillreturns
In the previous implementation, we kept the first variable in the return statement that matched the each given return type. Now, we keep searching for a non-"zero" value, even if we have already found a "zero" value. Change-Id: Icf0987bab90239781452319979e7a30502807e36 Reviewed-on: https://go-review.googlesource.com/c/tools/+/246917 Run-TryBot: Josh Baum <joshbaum@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
990129eca5
commit
1c672e2dff
|
|
@ -135,8 +135,14 @@ outer:
|
|||
if !matchingTypes(info.TypeOf(val), typ) {
|
||||
continue
|
||||
}
|
||||
if !analysisinternal.IsZeroValue(val) {
|
||||
match, idx = val, j
|
||||
break
|
||||
}
|
||||
// If the current match is a "zero" value, we keep searching in
|
||||
// case we find a non-"zero" value match. If we do not find a
|
||||
// non-"zero" value, we will use the "zero" value.
|
||||
match, idx = val, j
|
||||
break
|
||||
}
|
||||
|
||||
if match != nil {
|
||||
|
|
|
|||
|
|
@ -118,5 +118,5 @@ func gotTooMany() int {
|
|||
} else {
|
||||
return 1 // want "wrong number of return values \\(want 1, got 3\\)"
|
||||
}
|
||||
return 0, 5 // want "wrong number of return values \\(want 1, got 3\\)"
|
||||
return 5 // want "wrong number of return values \\(want 1, got 3\\)"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue