From e8c8f0e7c0f59194f6f3b59af4a58d6d6634a373 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 10 Mar 2022 11:11:09 +0200 Subject: [PATCH] v.ast: fix `dump(os.real_path(Makefile))` printing `main.os.real_path` --- vlib/v/ast/str.v | 3 +++ vlib/v/tests/inout/dump_expression.out | 12 +++++++----- vlib/v/tests/inout/dump_expression.vv | 12 ++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index f232c0226f..e585bfc051 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -311,6 +311,9 @@ pub fn (x Expr) str() string { if x.mod == '' && x.name == '' { return x.left.str() + '($sargs)$propagate_suffix' } + if x.name.contains('.') { + return '${x.name}($sargs)$propagate_suffix' + } return '${x.mod}.${x.name}($sargs)$propagate_suffix' } CharLiteral { diff --git a/vlib/v/tests/inout/dump_expression.out b/vlib/v/tests/inout/dump_expression.out index 45cab3ebad..db5867f695 100644 --- a/vlib/v/tests/inout/dump_expression.out +++ b/vlib/v/tests/inout/dump_expression.out @@ -1,17 +1,19 @@ -[vlib/v/tests/inout/dump_expression.vv:2] 1: 1 -[vlib/v/tests/inout/dump_expression.vv:7] 'a': a -[vlib/v/tests/inout/dump_expression.vv:23] p: Point{ +[vlib/v/tests/inout/dump_expression.vv:4] 1: 1 +[vlib/v/tests/inout/dump_expression.vv:9] 'a': a +[vlib/v/tests/inout/dump_expression.vv:25] p: Point{ x: 1 y: 2 z: 3 } -[vlib/v/tests/inout/dump_expression.vv:24] p_mut: Point{ +[vlib/v/tests/inout/dump_expression.vv:26] p_mut: Point{ x: 1 y: 2 z: 3 } -[vlib/v/tests/inout/dump_expression.vv:25] p_ptr: &Point{ +[vlib/v/tests/inout/dump_expression.vv:27] p_ptr: &Point{ x: 1 y: 2 z: 3 } +[vlib/v/tests/inout/dump_expression.vv:38] os.file_name(vexe).replace('.exe', ''): v +[vlib/v/tests/inout/dump_expression.vv:41] f.read(mut buf): 10 diff --git a/vlib/v/tests/inout/dump_expression.vv b/vlib/v/tests/inout/dump_expression.vv index 7dc41b8535..6a0cbb4f11 100644 --- a/vlib/v/tests/inout/dump_expression.vv +++ b/vlib/v/tests/inout/dump_expression.vv @@ -1,3 +1,5 @@ +import os + fn dump_of_int() { x := dump(1) + 1 assert x == 2 @@ -31,8 +33,18 @@ fn dump_of_struct() { assert x3 == Point{101, 2, 3} } +fn dump_of_callexpr() { + vexe := @VEXE + dump(os.file_name(vexe).replace('.exe', '')) + mut f := os.open_file(os.join_path(os.dir(vexe), 'Makefile'), 'r') or { return } + mut buf := []byte{len:10} + dump( f.read(mut buf) or { -999 }) + f.close() +} + fn main() { dump_of_int() dump_of_string() dump_of_struct() + dump_of_callexpr() }