-
-
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.
v: add map update-init syntax: `new_map := {...old_map, 'k1': 1, 'k2'…
…: 5}` (#20561)
- Loading branch information
Showing
14 changed files
with
427 additions
and
72 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
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,14 @@ | ||
vlib/v/checker/tests/map_init_invalid_update.vv:8:6: error: invalid map update: non-map type | ||
6 | foo := 'foo is a string' | ||
7 | a := { | ||
8 | ...foo // not a map | ||
| ~~~ | ||
9 | 'a': 5 | ||
10 | 'b': 6 | ||
vlib/v/checker/tests/map_init_invalid_update.vv:19:6: error: invalid map update: non-map type | ||
17 | println(b) | ||
18 | c := { | ||
19 | ...Foo{9} // also not ok | ||
| ~~~~~~ | ||
20 | } | ||
21 | println(c) |
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,22 @@ | ||
struct Foo { | ||
x int | ||
} | ||
|
||
fn main() { | ||
foo := 'foo is a string' | ||
a := { | ||
...foo // not a map | ||
'a': 5 | ||
'b': 6 | ||
} | ||
println(a) | ||
b := { | ||
...(a.clone()) // ok | ||
'c': 99 | ||
} | ||
println(b) | ||
c := { | ||
...Foo{9} // also not ok | ||
} | ||
println(c) | ||
} |
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 @@ | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:18:9: error: invalid map value: expected `int`, not `string` | ||
16 | b := Bar{ | ||
17 | m: { | ||
18 | 'a': '5' | ||
| ~~~ | ||
19 | 'b': '6' | ||
20 | } // bad | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:19:9: error: invalid map value: expected `int`, not `string` | ||
17 | m: { | ||
18 | 'a': '5' | ||
19 | 'b': '6' | ||
| ~~~ | ||
20 | } // bad | ||
21 | } | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:36:9: error: invalid map value: expected `int`, not `string` | ||
34 | m: { | ||
35 | ...a.m | ||
36 | 'c': '7' | ||
| ~~~ | ||
37 | } // bad values | ||
38 | } | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:43:9: error: invalid map update: expected `map[string]int`, not `map[string]string` | ||
41 | f := Bar{ | ||
42 | m: { | ||
43 | ...x.m | ||
| ^ | ||
44 | } // bad update | ||
45 | } | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:48:9: error: invalid map update: expected `map[string]int`, not `map[string]string` | ||
46 | g := Bar{ | ||
47 | m: { | ||
48 | ...x.m | ||
| ^ | ||
49 | 'c': 7 | ||
50 | } // bad update, ok values | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:54:9: error: invalid map update: expected `map[string]int`, not `map[string]string` | ||
52 | h := Bar{ | ||
53 | m: { | ||
54 | ...x.m | ||
| ^ | ||
55 | 'c': '7' | ||
56 | } // bad update, bad values | ||
vlib/v/checker/tests/map_init_wrong_expected_type.vv:55:9: error: invalid map value: expected `int`, not `string` | ||
53 | m: { | ||
54 | ...x.m | ||
55 | 'c': '7' | ||
| ~~~ | ||
56 | } // bad update, bad values | ||
57 | } |
Oops, something went wrong.