mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
This commit is contained in:
parent
7220f75b07
commit
4c55de5e65
3 changed files with 36 additions and 0 deletions
|
@ -517,6 +517,8 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
|
||||||
if node.keys.len == 1 && map_val_type == ast.none_type {
|
if node.keys.len == 1 && map_val_type == ast.none_type {
|
||||||
c.error('map value cannot be only `none`', node.vals[0].pos())
|
c.error('map value cannot be only `none`', node.vals[0].pos())
|
||||||
}
|
}
|
||||||
|
c.check_expr_option_or_result_call(key_, map_key_type)
|
||||||
|
c.check_expr_option_or_result_call(val_, map_val_type)
|
||||||
}
|
}
|
||||||
map_key_type = c.unwrap_generic(map_key_type)
|
map_key_type = c.unwrap_generic(map_key_type)
|
||||||
map_val_type = c.unwrap_generic(map_val_type)
|
map_val_type = c.unwrap_generic(map_val_type)
|
||||||
|
@ -539,6 +541,8 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
|
||||||
val_type := c.expr(mut val)
|
val_type := c.expr(mut val)
|
||||||
node.val_types << val_type
|
node.val_types << val_type
|
||||||
val_type_sym := c.table.sym(val_type)
|
val_type_sym := c.table.sym(val_type)
|
||||||
|
c.check_expr_option_or_result_call(key, key_type)
|
||||||
|
c.check_expr_option_or_result_call(val, val_type)
|
||||||
if !c.check_types(key_type, map_key_type)
|
if !c.check_types(key_type, map_key_type)
|
||||||
|| (i == 0 && key_type.is_number() && map_key_type.is_number()
|
|| (i == 0 && key_type.is_number() && map_key_type.is_number()
|
||||||
&& map_key_type != ast.mktyp(key_type)) {
|
&& map_key_type != ast.mktyp(key_type)) {
|
||||||
|
|
21
vlib/v/checker/tests/map_key_val_or_not_progagate_err.out
Normal file
21
vlib/v/checker/tests/map_key_val_or_not_progagate_err.out
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
vlib/v/checker/tests/map_key_val_or_not_progagate_err.vv:6:7: error: f() returns `!int`, so it should have either an `or {}` block, or `!` at the end
|
||||||
|
4 |
|
||||||
|
5 | a := {
|
||||||
|
6 | 2: f() // first value
|
||||||
|
| ~~~
|
||||||
|
7 | 3: f() // second value
|
||||||
|
8 | f(): 1
|
||||||
|
vlib/v/checker/tests/map_key_val_or_not_progagate_err.vv:7:7: error: f() returns `!int`, so it should have either an `or {}` block, or `!` at the end
|
||||||
|
5 | a := {
|
||||||
|
6 | 2: f() // first value
|
||||||
|
7 | 3: f() // second value
|
||||||
|
| ~~~
|
||||||
|
8 | f(): 1
|
||||||
|
9 | }
|
||||||
|
vlib/v/checker/tests/map_key_val_or_not_progagate_err.vv:8:2: error: f() returns `!int`, so it should have either an `or {}` block, or `!` at the end
|
||||||
|
6 | 2: f() // first value
|
||||||
|
7 | 3: f() // second value
|
||||||
|
8 | f(): 1
|
||||||
|
| ~~~
|
||||||
|
9 | }
|
||||||
|
10 |
|
11
vlib/v/checker/tests/map_key_val_or_not_progagate_err.vv
Normal file
11
vlib/v/checker/tests/map_key_val_or_not_progagate_err.vv
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fn f() !int {
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
|
||||||
|
a := {
|
||||||
|
2: f() // first value
|
||||||
|
3: f() // second value
|
||||||
|
f(): 1
|
||||||
|
}
|
||||||
|
|
||||||
|
println(a)
|
Loading…
Add table
Add a link
Reference in a new issue