From 1b09e37a8047bc97d4b6901e778da8ae044e14c1 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 10 Jul 2019 14:38:39 +0200 Subject: [PATCH] fix typ_to_fmt() --- compiler/fn.v | 2 +- compiler/parser.v | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/fn.v b/compiler/fn.v index 1534e7bfbb..ce45b6177c 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -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 diff --git a/compiler/parser.v b/compiler/parser.v index d13e6f40fd..66ab24ac45 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -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" ') }