fix typ_to_fmt()
parent
c8fc262da3
commit
1b09e37a80
|
@ -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
|
||||
|
|
|
@ -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" ')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue