v4 / vlib / v / tests / skip_unused / interface_mut_receiver_anon_fn.vv
34 lines · 27 sloc · 624 bytes · 005e49db7134829bdcd2f29b16273fee70f81a84
Raw
1module main
2
3// Regression test for https://github.com/vlang/v/issues/27354
4// An anon fn passed to a C callback inside a method that is reached only via
5// interface dispatch on a `mut` receiver must be marked used by markused,
6// otherwise -skip-unused (the default) drops its definition and the generated
7// C fails with `use of undeclared identifier 'anon_fn_...'`.
8
9fn C.atexit(cb voidptr) int
10
11interface Handler {
12 setup()
13}
14
15struct Impl {
16mut:
17 n int
18}
19
20fn (mut i Impl) setup() {
21 C.atexit(fn () {})
22}
23
24fn run(mut h Handler) {
25 h.setup()
26}
27
28fn main() {
29 mut impl := Impl{
30 n: 99
31 }
32 run(mut impl)
33 println('done')
34}
35