From 45cbf4f14e25f5388f0487d466e55f0a7e3c85f9 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 29 Oct 2024 13:15:27 +0800 Subject: [PATCH] ast: improve the assert informations (related #22668) (#22679) --- vlib/v/ast/str.v | 11 ++++++++--- .../globals_run/function_stored_in_global.run.out | 6 +++--- vlib/v/slow_tests/inout/dump_sumtype_of_fntype.out | 2 +- .../assert_of_sumtype_values_works_test.run.out | 7 +++---- ...t_of_sumtype_values_works_test.skip_unused.run.out | 7 +++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index a9f10a5194..b2b196dd4a 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -450,7 +450,8 @@ pub fn (x &Expr) str() string { return x.val.str() } CastExpr { - return '${global_table.type_to_str(x.typ)}(${x.expr.str()})' + type_name := util.strip_main_name(global_table.type_to_str(x.typ)) + return '${type_name}(${x.expr.str()})' } CallExpr { sargs := args2str(x.args) @@ -476,7 +477,11 @@ pub fn (x &Expr) str() string { if x.name.contains('__static__') { return '${x.mod}.${x.get_name()}(${sargs})${propagate_suffix}' } - return '${x.mod}.${x.get_name()}(${sargs})${propagate_suffix}' + if x.mod == 'main' { + return '${x.get_name()}(${sargs})${propagate_suffix}' + } else { + return '${x.mod}.${x.get_name()}(${sargs})${propagate_suffix}' + } } CharLiteral { return '`${x.val}`' @@ -513,7 +518,7 @@ pub fn (x &Expr) str() string { return x.cached_name } unsafe { - x.cached_name = x.name.clone() + x.cached_name = util.strip_main_name(x.name.clone()) } return x.cached_name } diff --git a/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out b/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out index 586eac76aa..a38dd88cc3 100644 --- a/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out +++ b/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out @@ -1,4 +1,4 @@ -[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:14] voidptr(main.abc) == voidptr(cpu_get_id): true -[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:15] main.cpu_get_id(): 123 +[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:14] voidptr(abc) == voidptr(cpu_get_id): true +[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:15] cpu_get_id(): 123 [vlib/v/checker/tests/globals_run/function_stored_in_global.vv:16] abc(): 123 -[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:17] abc() == main.cpu_get_id(): true +[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:17] abc() == cpu_get_id(): true diff --git a/vlib/v/slow_tests/inout/dump_sumtype_of_fntype.out b/vlib/v/slow_tests/inout/dump_sumtype_of_fntype.out index e0f5280898..40a1900f6d 100644 --- a/vlib/v/slow_tests/inout/dump_sumtype_of_fntype.out +++ b/vlib/v/slow_tests/inout/dump_sumtype_of_fntype.out @@ -1 +1 @@ -[vlib/v/slow_tests/inout/dump_sumtype_of_fntype.vv:10] main.MyFnSumtype(main.f): MyFnSumtype(fn (int) v.ast.Expr) +[vlib/v/slow_tests/inout/dump_sumtype_of_fntype.vv:10] MyFnSumtype(f): MyFnSumtype(fn (int) v.ast.Expr) diff --git a/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.run.out b/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.run.out index a636931a34..10bd3479b8 100644 --- a/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.run.out +++ b/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.run.out @@ -4,7 +4,6 @@ vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:5: fn test_ab Right value (len: 6): `Sum(2)` vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:9: fn test_sumtype_literals - > assert main.Sum(1) == main.Sum(2) - Left value (len: 11): `main.Sum(1)` - Right value (len: 11): `main.Sum(2)` - + > assert Sum(1) == Sum(2) + Left value (len: 6): `Sum(1)` + Right value (len: 6): `Sum(2)` diff --git a/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.skip_unused.run.out b/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.skip_unused.run.out index a636931a34..10bd3479b8 100644 --- a/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.skip_unused.run.out +++ b/vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.skip_unused.run.out @@ -4,7 +4,6 @@ vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:5: fn test_ab Right value (len: 6): `Sum(2)` vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:9: fn test_sumtype_literals - > assert main.Sum(1) == main.Sum(2) - Left value (len: 11): `main.Sum(1)` - Right value (len: 11): `main.Sum(2)` - + > assert Sum(1) == Sum(2) + Left value (len: 6): `Sum(1)` + Right value (len: 6): `Sum(2)`