v4 / vlib / v / checker / tests / cast_voidptr_to_struct_alias_err.vv
28 lines · 20 sloc · 502 bytes · 0c8ce3bcb9fd4a2e5bd5f991a5a07da976d780d7
Raw
1module main
2
3// has `typedef`
4@[typedef]
5struct C.Foo1 {}
6
7type AliasFoo1 = C.Foo1
8
9// no `typedef`
10struct C.Foo2 {}
11
12type AliasFoo2 = C.Foo2
13
14struct Bar {}
15
16type AliasBar = Bar
17
18fn main() {
19 // test cast `voidptr/nil` to `alias`
20 _ = AliasFoo1(unsafe { nil })
21 _ = AliasFoo2(unsafe { nil })
22 _ = AliasBar(unsafe { nil })
23
24 // test cast `voidptr/nil` to `non-alias` and has `typedef`
25 _ = C.Foo1(unsafe { nil })
26 // test cast `voidptr/nil` to `non-alias` and no `typedef`
27 _ = C.Foo2(unsafe { nil })
28}
29