diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index e004e842ea..1642047440 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -203,6 +203,12 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F all_fn_root_names << k continue } + if mfn.receiver.typ != ast.void_type && mfn.receiver.typ.has_flag(.generic) { + // generic methods may be used in cgen after specialisation :-| + // TODO: move generic method specialisation from cgen to before markused + all_fn_root_names << k + continue + } // testing framework: if pref.is_test { if k.starts_with('test_') || k.contains('.test_') { diff --git a/vlib/v/tests/skip_unused/generics_method.run.out b/vlib/v/tests/skip_unused/generics_method.run.out new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/vlib/v/tests/skip_unused/generics_method.run.out @@ -0,0 +1 @@ +0 diff --git a/vlib/v/tests/skip_unused/generics_method.skip_unused.run.out b/vlib/v/tests/skip_unused/generics_method.skip_unused.run.out new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/vlib/v/tests/skip_unused/generics_method.skip_unused.run.out @@ -0,0 +1 @@ +0 diff --git a/vlib/v/tests/skip_unused/generics_method.vv b/vlib/v/tests/skip_unused/generics_method.vv new file mode 100644 index 0000000000..0d558c4660 --- /dev/null +++ b/vlib/v/tests/skip_unused/generics_method.vv @@ -0,0 +1,31 @@ +interface Something { + i int +} + +struct Some { + i int +} + +struct App { + f M +} + +fn (mut self App) next(input T) f64 { + $if M is Something { + return 0 + } $else { + panic('${typeof(M.typ).name} is not supported') + return 1 + } + return 1 +} + +fn main() { + mut app := App{ + f: Some{ + i: 10 + } + } + assert app.next(1) == 0 + println(app.next(1)) +}