Skip to content

spec: Order of multiple assignment using range is not clear #3464

@ianlancetaylor

Description

@ianlancetaylor
package main

func main() {
    var s [10]int
    var i int
    for i, s[i] = range [...]int{0, 1, 2, 3, 4} {
        println(i, s[i])
    }
}

In the range clause, it's not clear what value of i is used when setting s[i].  Is it
the new value for i or the previous one?

The description in the spec of multiple assignments suggests that the value used for
s[i] in the assignment should be determined before i is set.  However, that description
is in a paragraph describing the multiple assignment case in which the number of
operands on the left is the same as the number of operands on the right.  It's not clear
whether that description also applies to range, or for that matter to the other
operations that can produce multiple results.

If range should act like other multiple assignments, then the spec should be clarified
and there is a bug in 6g (but not in gccgo).  If range should not act like other
multiple assignments, then how should it act?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions