From e1eb9c4ff11f6aa84746960679b3021bfedaac1d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 21 Jul 2020 15:58:17 +0300 Subject: [PATCH] vfmt: fix `x := *&int(ptr)` --- vlib/v/fmt/fmt.v | 2 +- vlib/v/fmt/tests/star__amp_int__cast_keep.vv | 5 +++++ vlib/v/parser/pratt.v | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/star__amp_int__cast_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index df7548c9a4..d265099198 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -898,7 +898,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) { } ast.PrefixExpr { f.write(node.op.str()) - f.expr(node.right) + f.prefix_expr_cast_expr( node.right ) } ast.RangeExpr { f.expr(node.low) diff --git a/vlib/v/fmt/tests/star__amp_int__cast_keep.vv b/vlib/v/fmt/tests/star__amp_int__cast_keep.vv new file mode 100644 index 0000000000..73312cd5e1 --- /dev/null +++ b/vlib/v/fmt/tests/star__amp_int__cast_keep.vv @@ -0,0 +1,5 @@ +fn main() { + body := [1, 2, 3] + size := *&int(body.data) + eprintln('size: $size') +} diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v index 7a3831bcb0..6a9084cabe 100644 --- a/vlib/v/parser/pratt.v +++ b/vlib/v/parser/pratt.v @@ -8,6 +8,10 @@ import v.table import v.token pub fn (mut p Parser) expr(precedence int) ast.Expr { + $if trace_parser ? { + tok_pos := p.tok.position() + eprintln('parsing file: ${p.file_name:-30} | tok.kind: ${p.tok.kind:-10} | tok.lit: ${p.tok.lit:-10} | tok_pos: ${tok_pos.str():-45} | expr($precedence)') + } // println('\n\nparser.expr()') mut typ := table.void_type mut node := ast.Expr{}