1
0
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:
yuyi 2022-01-10 15:12:46 +08:00 committed by GitHub
parent 7f1cc44b04
commit 02f791d9fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -202,7 +202,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
sym := c.table.sym(c.expected_type)
if sym.kind == .map {
info := sym.map_info()
node.typ = c.expected_type
node.typ = c.expected_type.clear_flag(.optional)
node.key_type = info.key_type
node.value_type = info.value_type
return node.typ

View 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' == '{}'
}