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
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
N/A
What did you do?
package main
import ("errors";"fmt")
func main() {
var s [1]int
s[0], err1 := 1, errors.New("some error") // error: non-name s[0] on left side of :=
fmt.Printf("%v\n", err1)
var err2 error
s[0], err2 = 1, errors.New("some error") // all good
fmt.Printf("%v %v\n", s[0], err2)
var i int
i, err3 := 1, errors.New("some other error") // all good
fmt.Printf("%v %v", i, err3)
}
if I change the operation to multiple assignment (pre-initialise err2), everything works as expected.
if instead of s[i] (dereferencing an array) I use a single value (var i int), the mixed assignment/short declaration works as advertised.
What did you expect to see?
at best I would expect Go to compile the program (not an unreasonable expectation IMO; given that multiple initialisation works, I don't see why short var declaration wouldn't).
at the very least I would expect a better compiler error.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?N/A
What did you do?
You can try it out here: https://play.golang.org/p/OIy7TJWnSkF
What did you see?
err2
), everything works as expected.s[i]
(dereferencing an array) I use a single value (var i int
), the mixed assignment/short declaration works as advertised.What did you expect to see?
The text was updated successfully, but these errors were encountered: