Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v: allow
none
for not first values on map initialization (#18821)
- Loading branch information
Showing
5 changed files
with
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
vlib/v/checker/tests/map_with_none_err.vv:2:6: warning: unused variable: `a` | ||
1 | fn main() { | ||
2 | mut a := { | ||
| ^ | ||
3 | 'bar': none | ||
4 | } | ||
vlib/v/checker/tests/map_with_none_err.vv:6:6: warning: unused variable: `b` | ||
4 | } | ||
5 | | ||
6 | mut b := { | ||
| ^ | ||
7 | 'foo': 1, | ||
8 | 'bar': none | ||
vlib/v/checker/tests/map_with_none_err.vv:11:6: warning: unused variable: `c` | ||
9 | } | ||
10 | | ||
11 | mut c := { | ||
| ^ | ||
12 | 'foo': ?int(none), | ||
13 | 'bar': none | ||
vlib/v/checker/tests/map_with_none_err.vv:3:10: error: map value cannot be only `none` | ||
1 | fn main() { | ||
2 | mut a := { | ||
3 | 'bar': none | ||
| ~~~~ | ||
4 | } | ||
5 | | ||
vlib/v/checker/tests/map_with_none_err.vv:8:10: error: invalid map value: expected `int`, not `none` | ||
6 | mut b := { | ||
7 | 'foo': 1, | ||
8 | 'bar': none | ||
| ~~~~ | ||
9 | } | ||
10 | |
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 @@ | ||
fn main() { | ||
mut a := { | ||
'bar': none | ||
} | ||
|
||
mut b := { | ||
'foo': 1, | ||
'bar': none | ||
} | ||
|
||
mut c := { | ||
'foo': ?int(none), | ||
'bar': none | ||
} | ||
} |
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,17 @@ | ||
fn test_main() { | ||
mut a := { | ||
'foo': ?int(1) | ||
'bar': none | ||
} | ||
a['foo'] = 1 | ||
assert dump(a) == a | ||
} | ||
|
||
fn test_none() { | ||
mut a := { | ||
'foo': ?int(1) | ||
'bar': none | ||
} | ||
a['foo'] = none | ||
assert dump(a) == a | ||
} |