1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
d2verb
2019-07-15 19:33:18 +09:00
committed by Alexander Medvednikov
parent 0556f5fd4e
commit 916b13b286
3 changed files with 79 additions and 6 deletions

View File

@ -2303,10 +2303,12 @@ fn (p mut Parser) map_init() string {
if !p.table.known_type(val_type) {
p.error('map init unknown type "$val_type"')
}
typ := 'map_$val_type'
p.register_map(typ)
p.gen('new_map(1, sizeof($val_type))')
p.check(.lcbr)
p.check(.rcbr)
return 'map_$val_type'
return typ
}
// [1,2,3]

View File

@ -543,11 +543,21 @@ fn type_default(typ string) string {
}
// Default values for other types are not needed because of mandatory initialization
switch typ {
case 'int': return '0'
case 'string': return 'tos("", 0)'
case 'void*': return '0'
case 'byte*': return '0'
case 'bool': return '0'
case 'string': return 'tos("", 0)'
case 'i8': return '0'
case 'i16': return '0'
case 'i32': return '0'
case 'u8': return '0'
case 'u16': return '0'
case 'u32': return '0'
case 'byte': return '0'
case 'int': return '0'
case 'rune': return '0'
case 'f32': return '0.0'
case 'f64': return '0.0'
case 'byteptr': return '0'
case 'voidptr': return '0'
}
return '{}'
return ''