FAQ
After upgrading from 1.2 to 1.3, I came across a peculiar inconsistency.

I had a struct that I was mutating in a return statement, and the return
value was an interface. Weirdly, this mutation worked in 1.2, but failed in
1.3.

Here's an example:
http://play.golang.org/p/zvwEnIKMl5

1.3 has the following output:

Fails 0
Works 999
Works 999


And 1.2 has the following output:

Fails 999
Works 999

Works 999


I'm not sure if this is documented behavior or not.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Dan Kortschak at Aug 1, 2014 at 2:31 am

    On Thu, 2014-07-31 at 19:05 -0700, trey@jellolabs.com wrote:
    I had a struct that I was mutating in a return statement, and the
    return
    value was an interface. Weirdly, this mutation worked in 1.2, but
    failed in
    1.3.

    Here's an example:
    http://play.golang.org/p/zvwEnIKMl5

    1.3 has the following output:

    Fails 0
    Works 999
    Works 999


    And 1.2 has the following output:

    Fails 999
    Works 999

    Works 999


    I'm not sure if this is documented behavior or not.
    Don't do that. If you want the operation on the *X to happen first, do
    it first.

    http://golang.org/ref/spec#Order_of_evaluation
    http://golang.org/ref/spec#Assignments

    """
    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.
    """

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jesse McNelis at Aug 1, 2014 at 3:54 am

    On Fri, Aug 1, 2014 at 12:05 PM, wrote:
    I'm not sure if this is documented behavior or not.
    http://golang.org/ref/spec#Order_of_evaluation
    The behaviour is documented, but it's documented as 'unspecified'.
    'unspecified' is short for "don't do that"

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 1, '14 at 2:05a
activeAug 1, '14 at 3:54a
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase