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

v: implement assignable anon struct #23857

Merged
merged 4 commits into from
Mar 5, 2025

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Mar 4, 2025

Fix #23855

mutable anon struct

mut var := struct { ... }
Makes the anon struct mutable

fn t() int {
	return 123
}

fn r(a struct { name string age int }) {
	assert '${a}' == "struct {
    name: 'Foo'
    age: 123
}"
}

fn test_main() {
	mut a := struct {
		name: 'Foo'
		age:  t()
	}
	dump(a)
	r(a)
	r(struct { name: 'Foo', age: t() })
	a.age = 2
	assert '${a}' == "struct {
    name: 'Foo'
    age: 2
}"
}

@felipensp felipensp changed the title v: implement assignable anon struct v: implement assignable anon struct *wip* Mar 4, 2025
Copy link

Connected to Huly®: V_0.6-22261

@felipensp felipensp changed the title v: implement assignable anon struct *wip* v: implement assignable anon struct Mar 4, 2025
@felipensp felipensp marked this pull request as ready for review March 4, 2025 23:16
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some next level wizardry...
Respect 🙇🏻‍♂️.

@spytheman spytheman merged commit 1ba8021 into vlang:master Mar 5, 2025
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow anonymous structures to be created on the fly
2 participants