mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: handles printing of structures and arrays of structures
This commit is contained in:

committed by
Alexander Medvednikov

parent
232532ba3b
commit
780ddaf22b
@ -2547,7 +2547,18 @@ fn (p mut Parser) string_expr() {
|
||||
else {
|
||||
f := p.typ_to_fmt(typ, 0)
|
||||
if f == '' {
|
||||
p.error('unhandled sprintf format "$typ" ')
|
||||
is_array := typ.starts_with('array_')
|
||||
has_str_method := p.table.type_has_method(p.table.find_type(typ), 'str')
|
||||
if is_array || has_str_method {
|
||||
if is_array && !has_str_method {
|
||||
p.gen_array_str(mut p.table.find_type(typ))
|
||||
}
|
||||
args = args.all_before_last(val) + '${typ}_str(${val}).len, ${typ}_str(${val}).str'
|
||||
format += '%.*s '
|
||||
}
|
||||
else {
|
||||
p.error('unhandled sprintf format "$typ" ')
|
||||
}
|
||||
}
|
||||
format += f
|
||||
}
|
||||
|
Reference in New Issue
Block a user