You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func generateNumberAndError() (int, error) {
return 1, errors.New("Test")
}
func main() {
var err error
if true {
i, err := generateNumberAndError()
fmt.Println(i)
fmt.Println(err)
}
fmt.Println(err) // Expecting "Test", but receiving nil
}
What did you expect to see?
"Test"
What did you see instead?
nil
Workarounds
func generateNumberAndError() (int, error) {
return 1, errors.New("Test")
}
func main() {
var err error
var i int
if true {
i, err = generateNumberAndError()
fmt.Println(i)
fmt.Println(err)
}
fmt.Println(err) // Works
}
But this is not feasible for situations where multiple return values are needed. It would unnecessarily bloat the code.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Reproducible in go.dev/play with Go 1.19
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Just using go.dev/play here
What did you do?
https://go.dev/play/p/VF4NlYvP7ce
What did you expect to see?
"Test"
What did you see instead?
nil
Workarounds
But this is not feasible for situations where multiple return values are needed. It would unnecessarily bloat the code.
The text was updated successfully, but these errors were encountered: