mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix returning optional empty map (#13113)
This commit is contained in:
@@ -202,7 +202,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
|
|||||||
sym := c.table.sym(c.expected_type)
|
sym := c.table.sym(c.expected_type)
|
||||||
if sym.kind == .map {
|
if sym.kind == .map {
|
||||||
info := sym.map_info()
|
info := sym.map_info()
|
||||||
node.typ = c.expected_type
|
node.typ = c.expected_type.clear_flag(.optional)
|
||||||
node.key_type = info.key_type
|
node.key_type = info.key_type
|
||||||
node.value_type = info.value_type
|
node.value_type = info.value_type
|
||||||
return node.typ
|
return node.typ
|
||||||
|
|||||||
13
vlib/v/tests/option_empty_map_test.v
Normal file
13
vlib/v/tests/option_empty_map_test.v
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
fn opt() ?map[string]string {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_option_empty_map() {
|
||||||
|
x := opt() or {
|
||||||
|
assert false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dump(x)
|
||||||
|
assert '$x' == '{}'
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user