Skip to content

v: implement assignable anon struct - #23857

Merged
spytheman merged 4 commits into
vlang:masterfrom
felipensp:allow_assign_anon_struct
Mar 5, 2025
Merged

spytheman merged 4 commits into
vlang:masterfrom
felipensp:allow_assign_anon_struct

Conversation

@felipensp

@felipensp felipensp commented Mar 4, 2025 •

Copy link
Copy Markdown
Member

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
@huly-for-github

Copy link
Copy Markdown

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

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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
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