1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fix typ_to_fmt()

This commit is contained in:
Alexander Medvednikov 2019-07-10 14:38:39 +02:00
parent c8fc262da3
commit 1b09e37a80
2 changed files with 5 additions and 5 deletions

View File

@ -696,7 +696,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
// (If we don't check for void, then V will compile `println(func())`)
if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' {
T := p.table.find_type(typ)
fmt := p.typ_to_fmt(typ)
fmt := p.typ_to_fmt(typ, 0)
if fmt != '' {
p.cgen.cur_line = p.cgen.cur_line.replace('println (', '/*opt*/printf ("' + fmt + '\\n", ')
continue

View File

@ -2135,7 +2135,7 @@ fn (p mut Parser) char_expr() {
}
fn (p mut Parser) typ_to_fmt(typ string) string {
fn (p mut Parser) typ_to_fmt(typ string, level int) string {
t := p.table.find_type(typ)
if t.is_enum {
return '%d'
@ -2155,8 +2155,8 @@ fn (p mut Parser) typ_to_fmt(typ string) string {
return '%p'
}
}
if t.parent != '' {
return p.typ_to_fmt(t.parent)
if t.parent != '' && level == 0 {
return p.typ_to_fmt(t.parent, level+1)
}
return ''
}
@ -2230,7 +2230,7 @@ fn (p mut Parser) string_expr() {
p.next()
}
else {
f := p.typ_to_fmt(typ)
f := p.typ_to_fmt(typ, 0)
if f == '' {
p.error('unhandled sprintf format "$typ" ')
}