diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index b993ae29e1d03c..208d4e39e647fc 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -1142,8 +1142,7 @@ fn struct_auto_str_func(sym &ast.TypeSymbol, lang ast.Language, _field_type ast. } return 'indent_${fn_name}(${obj}, indent_count + 1)', true } else if sym.kind == .function { - obj := '${deref}it${op}${final_field_name}${sufix}' - return '${fn_name}(${obj})', true + return '${fn_name}()', true } else if sym.kind == .chan { return '${fn_name}(${deref}it${op}${final_field_name}${sufix})', true } else if sym.kind == .thread { diff --git a/vlib/v/gen/c/testdata/struct_fn_member_print.c.must_have b/vlib/v/gen/c/testdata/struct_fn_member_print.c.must_have new file mode 100644 index 00000000000000..5c9dd8b26d7d37 --- /dev/null +++ b/vlib/v/gen/c/testdata/struct_fn_member_print.c.must_have @@ -0,0 +1,3 @@ +static string main__MyStruct_str(main__MyStruct it) { return indent_main__MyStruct_str(it, 0);} +static string main__Function_str() { return _SLIT("fn (int)");} +string _t1 = main__Function_str(); \ No newline at end of file diff --git a/vlib/v/gen/c/testdata/struct_fn_member_print.out b/vlib/v/gen/c/testdata/struct_fn_member_print.out new file mode 100644 index 00000000000000..24e87372f3ff0a --- /dev/null +++ b/vlib/v/gen/c/testdata/struct_fn_member_print.out @@ -0,0 +1,3 @@ +MyStruct{ + func: fn (int) +} diff --git a/vlib/v/gen/c/testdata/struct_fn_member_print.vv b/vlib/v/gen/c/testdata/struct_fn_member_print.vv new file mode 100644 index 00000000000000..77ecd825fbe44f --- /dev/null +++ b/vlib/v/gen/c/testdata/struct_fn_member_print.vv @@ -0,0 +1,18 @@ +module main + +type Function = fn (int) + +struct MyStruct { + func Function @[required] +} + +fn implementation(size int) { + println('size is ${size}') +} + +fn main() { + m := MyStruct{ + func: implementation + } + println('${m}') +} \ No newline at end of file