-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix checking match branch call expr twice
- Loading branch information
Showing
3 changed files
with
88 additions
and
10 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
28 changes: 28 additions & 0 deletions
28
vlib/v/checker/tests/match_branch_call_expr_arg_mismatch.out
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,28 @@ | ||
vlib/v/checker/tests/match_branch_call_expr_arg_mismatch.vv:16:19: error: cannot use `&Foobar` as `&Foo` in argument 1 to `mutate_foo` | ||
14 | match foobar { | ||
15 | Foo { | ||
16 | mutate_foo(mut foobar) | ||
| ~~~~~~ | ||
17 | } | ||
18 | Bar { | ||
vlib/v/checker/tests/match_branch_call_expr_arg_mismatch.vv:19:19: error: cannot use `&Foobar` as `&Bar` in argument 1 to `mutate_bar` | ||
17 | } | ||
18 | Bar { | ||
19 | mutate_bar(mut foobar) | ||
| ~~~~~~ | ||
20 | } | ||
21 | } | ||
vlib/v/checker/tests/match_branch_call_expr_arg_mismatch.vv:27:19: error: cannot use `&Foobar` as `&Foo` in argument 1 to `mutate_foo` | ||
25 | return match foobar { | ||
26 | Foo { | ||
27 | mutate_foo(mut foobar) | ||
| ~~~~~~ | ||
28 | } | ||
29 | Bar { | ||
vlib/v/checker/tests/match_branch_call_expr_arg_mismatch.vv:30:19: error: cannot use `&Foobar` as `&Bar` in argument 1 to `mutate_bar` | ||
28 | } | ||
29 | Bar { | ||
30 | mutate_bar(mut foobar) | ||
| ~~~~~~ | ||
31 | } | ||
32 | } |
49 changes: 49 additions & 0 deletions
49
vlib/v/checker/tests/match_branch_call_expr_arg_mismatch.vv
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,49 @@ | ||
struct Foo { | ||
mut: | ||
x int | ||
} | ||
|
||
struct Bar { | ||
mut: | ||
y int | ||
} | ||
|
||
type Foobar = Foo | Bar | ||
|
||
fn mutate_foobar1(mut foobar Foobar) { | ||
match foobar { | ||
Foo { | ||
mutate_foo(mut foobar) | ||
} | ||
Bar { | ||
mutate_bar(mut foobar) | ||
} | ||
} | ||
} | ||
|
||
fn mutate_foobar2(mut foobar Foobar) int { | ||
return match foobar { | ||
Foo { | ||
mutate_foo(mut foobar) | ||
} | ||
Bar { | ||
mutate_bar(mut foobar) | ||
} | ||
} | ||
} | ||
|
||
fn mutate_foo(mut foo Foo) int { | ||
foo.x = 5 | ||
return 5 | ||
} | ||
|
||
fn mutate_bar(mut bar Bar) int { | ||
bar.y = 10 | ||
return 10 | ||
} | ||
|
||
fn main() { | ||
mut bar := Bar{y: 0} | ||
mutate_foobar1(mut bar) | ||
mutate_foobar2(mut bar) | ||
} |