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

checker, cgen: fix auto dereference mut variable in if expr (fix #21309) #21720

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jun 24, 2024

This PR fix auto dereference mut variable in if expr (fix #21309).

  • Fix auto dereference mut variable in if expr.
  • Add test.
struct Foo {
	str string
}

fn (mut f Foo) foo(f2 Foo) string {
	return (if f.str != '' {
		f
	} else {
		f2
	}).str
}

fn main() {
	mut foo := Foo{}
	dump(foo.foo(Foo{ str: 'a' }))
	assert foo.foo(Foo{ str: 'a' }) == 'a'
}

PS D:\Test\v\tt1> v run .
[.\\tt1.v:15] foo.foo(main.Foo{....}): a

@spytheman spytheman merged commit 2b0938d into vlang:master Jun 24, 2024
76 checks passed
@yuyi98 yuyi98 deleted the fix_auto_deref_in_if_expr branch June 24, 2024 14:29
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.

builder error: when using selector expression on expression (missing autoderef in method?)
2 participants