Storing an arena value somewhere older
Ordinary values are copied out of an arena when they escape, but an owner is not. It holds memory the arena is about to release, and a copy would give it a second release. Storing one into a container that outlives the block is reported, naming both values.
The error suggests two fixes: build the buffer outside the block, or select the array's allocator with context.allocator.use(..) before building the buffer, so both live in the same place.
fn main() {
let mut rows = Array.new<Buffer>()
defer rows.deinit()
{
context.allocator.use(.Arena)
let mut row = Buffer.new()
errdefer row.deinit()
row.append("moon").unwrap()
rows.append(row).unwrap()
}
println(rows.len())
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Try Check. Expected diagnostic: still holds it
Ctrl/⌘+Enter checks the current lesson.