| 1 | module 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 | |
| 9 | fn C.atexit(cb voidptr) int |
| 10 | |
| 11 | interface Handler { |
| 12 | setup() |
| 13 | } |
| 14 | |
| 15 | struct Impl { |
| 16 | mut: |
| 17 | n int |
| 18 | } |
| 19 | |
| 20 | fn (mut i Impl) setup() { |
| 21 | C.atexit(fn () {}) |
| 22 | } |
| 23 | |
| 24 | fn run(mut h Handler) { |
| 25 | h.setup() |
| 26 | } |
| 27 | |
| 28 | fn main() { |
| 29 | mut impl := Impl{ |
| 30 | n: 99 |
| 31 | } |
| 32 | run(mut impl) |
| 33 | println('done') |
| 34 | } |
| 35 | |