Skip to content

Incorrect lhs evaluation order in multi-assignments #1063

Closed
@nevkontakte

Description

@nevkontakte

The spec says the following:

The assignment proceeds in two phases. First, the operands of index expressions and pointer indirections (including implicit pointer indirections in selectors) on the left and the expressions on the right are all evaluated in the usual order. Second, the assignments are carried out in left-to-right order.

However, gopherjs evaluates lhs expressions at the time of assignment. In situations when one of the assignments modifies a variable referenced by another assignment, the result may be incorrect. For example:

package main

func main() {
        type T struct{ i int }
        var x T
        p := &x
        p, p.i = new(T), 4
        println(p.i, x.i)
}

Go prints 0 4
GopherJS prints 4 0

Related: golang/go#23017.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions