v / vlib / v2 / gen / cleanc / tests / map_empty_init.v
20 lines · 17 sloc · 484 bytes · cd518ca93cb73cc164af43c1a07f74a9240b433b
Raw
1module main
2
3fn make_empty() map[string]int {
4 return {}
5}
6
7fn main() {
8 // Empty shorthand map literal `{}` should lower to a correct runtime map constructor.
9 mut m := make_empty()
10 key1 := 'abc'
11 key2 := key1.clone() // Ensure key equality is based on string content, not pointer identity.
12 m[key1] = 123
13 println(m[key2])
14 println(m['missing'])
15
16 // Typed empty map init should also lower to a runtime map constructor.
17 mut m2 := map[string]int{}
18 m2['x'] = 7
19 println(m2['x'])
20}
21