ast: improve the assert informations (related #22668) (#22679)

This commit is contained in:
yuyi 2024-10-29 13:15:27 +08:00 committed by GitHub
parent 5495280e7d
commit 45cbf4f14e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 15 deletions

View File

@ -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,8 +477,12 @@ pub fn (x &Expr) str() string {
if x.name.contains('__static__') {
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
}

View File

@ -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

View File

@ -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)

View File

@ -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)`

View File

@ -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)`