-
-
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.
checker: restrict multiple union fields initialised at once with a ni…
…cer checker error, instead of producing an enigmatic error at cgen time (#22196)
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
vlib/v/checker/tests/union_init_having_more_fields_err.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,14 @@ | ||
vlib/v/checker/tests/union_init_having_more_fields_err.vv:23:7: error: embed union `Head` can have only one field initialised | ||
21 | | ||
22 | fn union_embed__having_more_fields_used() { | ||
23 | _ := Message{ | ||
| ~~~~~~~~ | ||
24 | from: 1 | ||
25 | src: 1 | ||
vlib/v/checker/tests/union_init_having_more_fields_err.vv:30:7: error: union `Head` can have only one field initialised | ||
28 | | ||
29 | fn union_having_more_fields_used() { | ||
30 | _ := Head{ | ||
| ~~~~~ | ||
31 | from: 1 | ||
32 | src: 1 |
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,34 @@ | ||
pub struct Lines { | ||
pub: | ||
from u8 | ||
to u8 | ||
dst u8 | ||
src u8 | ||
} | ||
|
||
pub union Head { | ||
Lines | ||
pub: | ||
serial [3]u8 | ||
} | ||
|
||
pub struct Message { | ||
Head | ||
pub: | ||
cmd u8 | ||
payload []u8 | ||
} | ||
|
||
fn union_embed__having_more_fields_used() { | ||
_ := Message{ | ||
from: 1 | ||
src: 1 | ||
} | ||
} | ||
|
||
fn union_having_more_fields_used() { | ||
_ := Head{ | ||
from: 1 | ||
src: 1 | ||
} | ||
} |