-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: fix fn mut argument of sumtype reference (#21874)
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 test_fn_mut_arg_of_sumtype_ref() { | ||
mut expr := &Expr1{} | ||
mut g := Gen{} | ||
ret := g.bar(mut expr) | ||
println(ret) | ||
assert ret == 'Expr1{}' | ||
} |