diff --git a/vlib/v/ast/scope.v b/vlib/v/ast/scope.v index 549391ea09a9fe..fb2ecc48d1640b 100644 --- a/vlib/v/ast/scope.v +++ b/vlib/v/ast/scope.v @@ -225,6 +225,17 @@ pub fn (s &Scope) has_inherited_vars() bool { return false } +pub fn (s &Scope) is_inherited_var(var_name string) bool { + for _, obj in s.objects { + if obj is Var { + if obj.is_inherited && obj.name == var_name { + return true + } + } + } + return false +} + pub fn (sc &Scope) show(depth int, max_depth int) string { mut out := '' mut indent := '' diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 7a310d97022668..ed109cb83b1f03 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -545,7 +545,8 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) string { name = name.replace_each(c_fn_name_escape_seq) } } - if node.is_anon && g.comptime.comptime_for_method_var != '' { + if node.is_anon && g.comptime.comptime_for_method_var != '' + && node.scope.is_inherited_var('method') { name = '${name}_${g.comptime.comptime_loop_id}' } if node.language == .c {