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

cgen: fix fn mut argument of sumtype reference (fix #21856) #21874

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jul 15, 2024

This PR fix fn mut argument of sumtype reference (fix #21856).

  • Fix fn mut argument of sumtype reference.
  • Add test.
module main

pub struct Expr1 {}

pub struct Expr2 {}

pub type Expr = Expr1 | Expr2

pub struct Gen {
}

fn (mut g Gen) foo(mut expr &Expr1) string {
	return '${expr}'
}

pub fn (mut g Gen) bar(mut expr Expr) string {
	return match mut expr {
		Expr1 { g.foo(mut &expr) }
		Expr2 { '' }
	}
}

fn main() {
	mut expr := &Expr1{}
	mut g := Gen{}
	ret := g.bar(mut expr)
	println(ret)
	assert ret == 'Expr1{}'
}

PS D:\Test\v\tt1> v run .       
Expr1{}

@spytheman spytheman merged commit aa34047 into vlang:master Jul 15, 2024
73 checks passed
@yuyi98 yuyi98 deleted the fix_smartcast_mut_arg branch July 15, 2024 13:30
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] match + &
3 participants