Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating/manipulating structs inside functions seems to blow things up #36

Open
Munchotaur opened this issue Oct 13, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Munchotaur
Copy link

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
}
@weiwenhao
Copy link
Member

I have successfully reproduced this bug, and I will fix it in the next version release.

@weiwenhao weiwenhao added the bug Something isn't working label Oct 13, 2023
@Munchotaur
Copy link
Author

Looking forward to testing it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants