Skip to content

Commit 45cbf4f

Browse files
authored
ast: improve the assert informations (related #22668) (#22679)
1 parent 5495280 commit 45cbf4f

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

vlib/v/ast/str.v

+8-3
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ pub fn (x &Expr) str() string {
450450
return x.val.str()
451451
}
452452
CastExpr {
453-
return '${global_table.type_to_str(x.typ)}(${x.expr.str()})'
453+
type_name := util.strip_main_name(global_table.type_to_str(x.typ))
454+
return '${type_name}(${x.expr.str()})'
454455
}
455456
CallExpr {
456457
sargs := args2str(x.args)
@@ -476,7 +477,11 @@ pub fn (x &Expr) str() string {
476477
if x.name.contains('__static__') {
477478
return '${x.mod}.${x.get_name()}(${sargs})${propagate_suffix}'
478479
}
479-
return '${x.mod}.${x.get_name()}(${sargs})${propagate_suffix}'
480+
if x.mod == 'main' {
481+
return '${x.get_name()}(${sargs})${propagate_suffix}'
482+
} else {
483+
return '${x.mod}.${x.get_name()}(${sargs})${propagate_suffix}'
484+
}
480485
}
481486
CharLiteral {
482487
return '`${x.val}`'
@@ -513,7 +518,7 @@ pub fn (x &Expr) str() string {
513518
return x.cached_name
514519
}
515520
unsafe {
516-
x.cached_name = x.name.clone()
521+
x.cached_name = util.strip_main_name(x.name.clone())
517522
}
518523
return x.cached_name
519524
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:14] voidptr(main.abc) == voidptr(cpu_get_id): true
2-
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:15] main.cpu_get_id(): 123
1+
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:14] voidptr(abc) == voidptr(cpu_get_id): true
2+
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:15] cpu_get_id(): 123
33
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:16] abc(): 123
4-
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:17] abc() == main.cpu_get_id(): true
4+
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:17] abc() == cpu_get_id(): true
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[vlib/v/slow_tests/inout/dump_sumtype_of_fntype.vv:10] main.MyFnSumtype(main.f): MyFnSumtype(fn (int) v.ast.Expr)
1+
[vlib/v/slow_tests/inout/dump_sumtype_of_fntype.vv:10] MyFnSumtype(f): MyFnSumtype(fn (int) v.ast.Expr)

vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.run.out

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:5: fn test_ab
44
Right value (len: 6): `Sum(2)`
55

66
vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:9: fn test_sumtype_literals
7-
> assert main.Sum(1) == main.Sum(2)
8-
Left value (len: 11): `main.Sum(1)`
9-
Right value (len: 11): `main.Sum(2)`
10-
7+
> assert Sum(1) == Sum(2)
8+
Left value (len: 6): `Sum(1)`
9+
Right value (len: 6): `Sum(2)`

vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.skip_unused.run.out

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:5: fn test_ab
44
Right value (len: 6): `Sum(2)`
55

66
vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:9: fn test_sumtype_literals
7-
> assert main.Sum(1) == main.Sum(2)
8-
Left value (len: 11): `main.Sum(1)`
9-
Right value (len: 11): `main.Sum(2)`
10-
7+
> assert Sum(1) == Sum(2)
8+
Left value (len: 6): `Sum(1)`
9+
Right value (len: 6): `Sum(2)`

0 commit comments

Comments
 (0)