From e13a7085188ab8fa5d9a4713cfed6f00477010b7 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 12 Jun 2026 10:02:29 +0300 Subject: [PATCH] compiler: walk mut interface dispatch dependencies (#27430) --- vlib/v/markused/walker.v | 6 +-- ...erface_dispatch_method_dependencies_test.v | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 vlib/v/tests/skip_unused/interface_dispatch_method_dependencies_test.v diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index d1ade5980..2b9fce094 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -3177,14 +3177,14 @@ pub fn (mut w Walker) mark_by_sym(isym ast.TypeSymbol) { } } ast.Interface { - for typ in isym.info.types { + for typ in isym.info.implementor_types(true) { if typ == ast.map_type { w.features.used_maps++ } w.mark_by_type(typ) - for method in isym.info.methods { + for method_name in isym.info.get_methods() { for ityp in [typ.set_nr_muls(1), typ.set_nr_muls(0)] { - mname := int(ityp.clear_flags()).str() + '.' + method.name + mname := int(ityp.clear_flags()).str() + '.' + method_name w.fn_by_name(mname) } } diff --git a/vlib/v/tests/skip_unused/interface_dispatch_method_dependencies_test.v b/vlib/v/tests/skip_unused/interface_dispatch_method_dependencies_test.v new file mode 100644 index 000000000..501ee1d88 --- /dev/null +++ b/vlib/v/tests/skip_unused/interface_dispatch_method_dependencies_test.v @@ -0,0 +1,48 @@ +import os + +const vexe = @VEXE + +fn test_skip_unused_walks_mut_interface_dispatch_method_dependencies() { + tmp_dir := os.join_path(os.vtmp_dir(), 'v_issue_27404') + os.mkdir_all(tmp_dir) or { panic(err) } + defer { + os.rmdir_all(tmp_dir) or {} + } + source_path := os.join_path(tmp_dir, 'issue_27404.v') + binary_path := os.join_path(tmp_dir, 'issue_27404') + source := [ + 'module main', + '', + 'interface Visitor {', + '\tvisit()', + '}', + '', + 'struct Han {', + 'mut:', + '\tn int', + '}', + '', + 'fn helper(s string) {', + '\tprintln(s)', + '}', + '', + 'fn (mut h Han) visit() {', + "\thelper('t')", + '}', + '', + 'fn run(mut v Visitor) {', + '\tv.visit()', + '}', + '', + 'fn main() {', + '\tmut h := Han{}', + '\trun(mut h)', + '}', + ].join('\n') + os.write_file(source_path, source) or { panic(err) } + res := + os.execute('${os.quoted_path(vexe)} -o ${os.quoted_path(binary_path)} ${os.quoted_path(source_path)}') + if res.exit_code != 0 { + panic(res.output) + } +} -- 2.39.5