Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: fix assigning array slice in struct init (#19150)
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
vlib/v/checker/tests/slice_clone_in_struct_init_notice.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,15 @@ | ||
vlib/v/checker/tests/slice_clone_in_struct_init_notice.vv:9:7: notice: an implicit clone of the slice was done here | ||
7 | | ||
8 | _ := AA{ | ||
9 | a: a[0..5] | ||
| ~~~~~~ | ||
10 | } | ||
11 | _ := a[0..5] | ||
Details: vlib/v/checker/tests/slice_clone_in_struct_init_notice.vv:9:7: details: To silence this notice, use either an explicit `a[..].clone()`, | ||
or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice. | ||
7 | | ||
8 | _ := AA{ | ||
9 | a: a[0..5] | ||
| ~~~~~~ | ||
10 | } | ||
11 | _ := a[0..5] |
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,12 @@ | ||
struct AA { | ||
a []int | ||
} | ||
|
||
fn main() { | ||
mut a := []int{len: 10} | ||
|
||
_ := AA{ | ||
a: a[0..5] | ||
} | ||
_ := a[0..5] | ||
} |