forked from vlang/v
-
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.
checker: avoid nil assign to option var (vlang#19746)
- Loading branch information
Showing
5 changed files
with
59 additions
and
3 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
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 @@ | ||
vlib/v/checker/tests/nil_to_option_err.vv:8:7: warning: cannot assign a reference to a value (this will be an error soon) left=int false right=nil true ptr=false | ||
6 | fn main() { | ||
7 | mut a := ?int(none) | ||
8 | a = unsafe { nil } | ||
| ^ | ||
9 | | ||
10 | mut b := Test{} | ||
vlib/v/checker/tests/nil_to_option_err.vv:7:9: warning: unused variable: `a` | ||
5 | | ||
6 | fn main() { | ||
7 | mut a := ?int(none) | ||
| ^ | ||
8 | a = unsafe { nil } | ||
9 | | ||
vlib/v/checker/tests/nil_to_option_err.vv:3:7: error: cannot assign `nil` to a non-pointer field | ||
1 | struct Test { | ||
2 | mut: | ||
3 | a ?int = unsafe { nil } | ||
| ~~~~ | ||
4 | } | ||
5 | | ||
vlib/v/checker/tests/nil_to_option_err.vv:8:9: error: cannot assign `nil` to option value | ||
6 | fn main() { | ||
7 | mut a := ?int(none) | ||
8 | a = unsafe { nil } | ||
| ~~~~~~ | ||
9 | | ||
10 | mut b := Test{} | ||
vlib/v/checker/tests/nil_to_option_err.vv:11:11: error: cannot assign `nil` to option value | ||
9 | | ||
10 | mut b := Test{} | ||
11 | b.a = unsafe { nil } | ||
| ~~~~~~ | ||
12 | } |
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 Test { | ||
mut: | ||
a ?int = unsafe { nil } | ||
} | ||
|
||
fn main() { | ||
mut a := ?int(none) | ||
a = unsafe { nil } | ||
|
||
mut b := Test{} | ||
b.a = unsafe { nil } | ||
} |
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