fix typ_to_fmt()

pull/1078/head
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 we don't check for void, then V will compile `println(func())`)
if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' { if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' {
T := p.table.find_type(typ) T := p.table.find_type(typ)
fmt := p.typ_to_fmt(typ) fmt := p.typ_to_fmt(typ, 0)
if fmt != '' { if fmt != '' {
p.cgen.cur_line = p.cgen.cur_line.replace('println (', '/*opt*/printf ("' + fmt + '\\n", ') p.cgen.cur_line = p.cgen.cur_line.replace('println (', '/*opt*/printf ("' + fmt + '\\n", ')
continue 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) t := p.table.find_type(typ)
if t.is_enum { if t.is_enum {
return '%d' return '%d'
@ -2155,8 +2155,8 @@ fn (p mut Parser) typ_to_fmt(typ string) string {
return '%p' return '%p'
} }
} }
if t.parent != '' { if t.parent != '' && level == 0 {
return p.typ_to_fmt(t.parent) return p.typ_to_fmt(t.parent, level+1)
} }
return '' return ''
} }
@ -2230,7 +2230,7 @@ fn (p mut Parser) string_expr() {
p.next() p.next()
} }
else { else {
f := p.typ_to_fmt(typ) f := p.typ_to_fmt(typ, 0)
if f == '' { if f == '' {
p.error('unhandled sprintf format "$typ" ') p.error('unhandled sprintf format "$typ" ')
} }