On Sat, Dec 28, 2024 at 5:38 PM Kaiming Yang <yaxu...@gmail.com> wrote: > > I'm trying to understand execution order of assignment statement, as spec > mentioned: > > > 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. > > I crafted a example about it: https://go.dev/play/p/6RulNQwIk4n, the core of > that example is this line: > > phase_2, foo.bar.value = "??????", compute_value() > > where `foo.bar.value` causes panic due to nil pointer. > > The execution result shows `compute_value()` is invoked, but `phase_2` > variable is not updated. Seems like the panic happened after phase 1 is > complete but before phase 2 started. > > I assume the panic should happen in one of two phases, but not in-between. If > panic happened in phase 1, `compute_value()` should not be invoked due to it > happen later in same phase; If panic happened in phase 2, `phase_2` variable > should have been changed already. > > Is the behavior working-as-indented? if so, what am I missing to understand > it?
Thanks. This looks like a bug to me. I think the panic should occur before compute_value is called. When I run your program with gccgo I get original panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4037fb] goroutine 1 [running]: main.main foo.go:22 Want to open a bug report at https://go.dev/issue? Thanks. Ian -- 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+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVj15Nf5KXo3pHT1yMLtFionhF2Abyb2AHe1Y0zvRDzzQ%40mail.gmail.com.