Skip to content

builtin, cgen: improve the assert informations (related #22666)#22668

Merged
spytheman merged 2 commits intovlang:masterfrom
yuyi98:improve_assert_info
Oct 27, 2024
Merged

builtin, cgen: improve the assert informations (related #22666)#22668
spytheman merged 2 commits intovlang:masterfrom
yuyi98:improve_assert_info

Conversation

@yuyi98
Copy link
Copy Markdown
Member

@yuyi98 yuyi98 commented Oct 27, 2024

This PR improve the assert informations (related #22666).

type Sum = int | string

fn main() {
	assert Sum(1) == Sum(2)
}

PS D:\Test\v\tt1> v run .    
.\\tt1.v:4: FAIL: fn main.main: assert main.Sum(1) == main.Sum(2)
  left value: main.Sum(1)
  right value: main.Sum(2)
V panic: Assertion failed...
v hash: 14b1a14
C:/Users/yuyi9/AppData/Local/Temp/v_0/tt1.01JB6ZGGR5EPG0CM0FD2MRVCFX.tmp.c:7314: at _v_panic: Backtrace
C:/Users/yuyi9/AppData/Local/Temp/v_0/tt1.01JB6ZGGR5EPG0CM0FD2MRVCFX.tmp.c:13684: by main__main
C:/Users/yuyi9/AppData/Local/Temp/v_0/tt1.01JB6ZGGR5EPG0CM0FD2MRVCFX.tmp.c:13721: by wmain
00466ea8 : by ???
0046700b : by ???
7ffe207e259d : by ???

Huly®: V_0.6-21117

@enghitalo
Copy link
Copy Markdown
Contributor

Great!!!

Copy link
Copy Markdown
Contributor

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

Please add a .vv/.out pair too in vlib/v/slow_tests/inout/ (include only the system independent part before the panic in the .out file; see ./vlib/v/slow_tests/inout/panic_on_fixed_array_slice.out for example) and it will be good to merge.

The _test.vv/.run.out pair is better to be placed in vlib/v/tests/skip_unused/, see below.

@spytheman
Copy link
Copy Markdown
Contributor

vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv with:

type Sum = int | string

fn test_ab() {
        a,b := Sum(1), Sum(2)
        assert a == b
}

fn test_sumtype_literals() {
        assert Sum(1) == Sum(2)
}

can be tested by vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.run.out:

vlib/v/tests/skip_unused/assert_of_sumtype_values_works_test.vv:5: fn test_ab
   > assert a == b
     Left value (len: 6): `Sum(1)`
    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)`
    

Can we remove the main. prefix, so that it is the same as the test_ab failure?

@spytheman
Copy link
Copy Markdown
Contributor

I've added the test pair.
You can test locally with VTEST_ONLY=assert_of_sumtype_values_works VAUTOFIX=1 ./v vlib/v/compiler_errors_test.v

@spytheman spytheman merged commit c8ddf21 into vlang:master Oct 27, 2024
@yuyi98 yuyi98 deleted the improve_assert_info branch October 28, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants