Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix auto str for fn struct member #21825

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions vlib/v/gen/c/auto_str_methods.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/c/testdata/struct_fn_member_print.c.must_have
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

3 changes: 3 additions & 0 deletions vlib/v/gen/c/testdata/struct_fn_member_print.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MyStruct{
func: fn (int)
}
18 changes: 18 additions & 0 deletions vlib/v/gen/c/testdata/struct_fn_member_print.vv
Original file line number Diff line number Diff line change
@@ -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}')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but do add newline in the end of file

Loading