Skip to content

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

Merged
spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_smartcast_mut_arg
Jul 15, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_smartcast_mut_arg

Conversation

@yuyi98

@yuyi98 yuyi98 commented Jul 15, 2024

Copy link
Copy Markdown
Member

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