Skip to content

cmd/compile: init info of OAS node in a select case is being dropped #48289

@danscales

Description

@danscales

Issues exists in current master (go1.18-devel), but has probably existed for a while.

When an OAS node is converted to an OSELRECV2 node in tcSelect(), any DCL node in the Init field (due to a := assignment) is being dropped, since a completely new node is being created and the Init field was not set.

Thanks for the test case created by @mdempsky:

package main

func main() {
	ch := make(chan int, 1)

	var ptrs [2]*int
	for i := range ptrs {
		ch <- i
		select {
		case x := <-ch:
			ptrs[i] = &x
		}
	}

	for i, ptr := range ptrs {
		if *ptr != i {
			println("FAIL:", *ptr, "!=", i)
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions