package main // Tests that heap allocations returned from functions survive the // dealloc sweep (escape detection works). Global store test removed // because package globals are immutable after init(). type Data struct { Val int32 } func returnPtr(v int32) (result *Data) { result = &Data{Val: v} return result } func allocAndRead(v int32) (out int32) { p := &Data{Val: v} out = p.Val return out } func main() { p := returnPtr(99) if p.Val == 99 { println("PASS: return escape survives dealloc") } else { println("FAIL: return escape corrupted") } v := allocAndRead(42) if v == 42 { println("PASS: local alloc read correctly") } else { println("FAIL: local alloc read corrupted") } }