import sync

struct St{
mut:
	n int
}

fn f(ch chan &St, sem sync.Semaphore) {
	w := St{}
	ch <- w
	mut x := St{}
	ch <- x
	// the following works
	y := &St{}
	ch <- y
	mut z := &St{}
	ch <- z
	sem.wait()
	println(z)
}

fn main() {
	c := chan &St{}
	sem := sync.new_semaphore()
	go f(c, sem)
	y := <-c
	// this should fail
	mut z := <-c
	z.n = 9
	sem.post()
	println(y)
	println(z)
}
