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
The two append() calls inside with_struct() happen before the first call to string(), but only if string() is used directly, not with a wrapper.
What did you expect to see?
In with_struct(), I expected string(append(arr1, 'c')) and string(append(arr2, 'd')) to be executed separately, not be interleaved.
It's also weird how adding a wrapper around string() makes the append() calls not interleaved. Is this actually due to intentional, undefined behavior? (due to go's relaxed order of evaluation rules)
Thanks @adesjardins-stripe, who originally brought this up in a Slack channel.
The text was updated successfully, but these errors were encountered:
In particular, the only two function calls in your struct literal expression are the two append calls. Those must appear to be evaluated in text order (first the 'c' append, then the d append). But []byte->string conversions are not one of the expression types that must be ordered. Both string conversions can happen after both appends.
So this isn't a bug. If you need to enforce ordering like this, you can use statement boundaries to do that (like your other examples).
Go version
go version go1.23.2 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I ran https://go.dev/play/p/oj2ayYHklaY.
What did you see happen?
The two
append()
calls insidewith_struct()
happen before the first call tostring()
, but only ifstring()
is used directly, not with a wrapper.What did you expect to see?
In
with_struct()
, I expectedstring(append(arr1, 'c'))
andstring(append(arr2, 'd'))
to be executed separately, not be interleaved.It's also weird how adding a wrapper around
string()
makes theappend()
calls not interleaved. Is this actually due to intentional, undefined behavior? (due to go's relaxed order of evaluation rules)Thanks @adesjardins-stripe, who originally brought this up in a Slack channel.
The text was updated successfully, but these errors were encountered: