nature
nature copied to clipboard
creating/manipulating structs inside functions seems to blow things up
Using nature 0.4.0-beta, I was messing around with structs.
I noticed that if this standalone function argh()
has the print statement with "Made it this far!" before the declaration of r2, the program compiles and runs just fine. Remove or comment out that print statement and there's a segmentation fault during the execution of the function.
Similar things seem to happen when I leave out the r2
variable entirely, and just perform arithmetic directly on the passed rectangle r
.
Maybe I'm misunderstanding the care and feeding of structs but this seems odd.
type rectangle = struct {
int width = 0
int length = 0
string name = ""
}
fn argh(rectangle r): rectangle {
r.width = 3
r.length = 4
println("Made it this far!")
var r2 = rectangle {
width = r.width * 2,
length = r.length * 2
}
println("Made it to here!")
return r2
}
I have successfully reproduced this bug, and I will fix it in the next version release.
Looking forward to testing it. Thanks!