v2 / vlib / v / tests / comptime / comptime_if_pointer_binding_test.v
20 lines · 18 sloc · 331 bytes · 4fab05f62db39b5fecdcc1b25b5f361220c3e98c
Raw
1fn type_name_of[U]() string {
2 return typeof[U]().name
3}
4
5fn pointee_name[T](val T) string {
6 _ = val
7 $if T is &V {
8 return type_name_of[V]()
9 } $else {
10 return typeof[T]().name
11 }
12}
13
14fn test_comptime_if_pointer_binding() {
15 x := 123
16 px := &x
17 ppx := &px
18 assert pointee_name(px) == 'int'
19 assert pointee_name(ppx) == '&int'
20}
21