mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen: fix auto str for fn struct member (#21825)
This commit is contained in:
parent
70e78cc766
commit
494be20564
4 changed files with 25 additions and 2 deletions
|
@ -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
|
return 'indent_${fn_name}(${obj}, indent_count + 1)', true
|
||||||
} else if sym.kind == .function {
|
} else if sym.kind == .function {
|
||||||
obj := '${deref}it${op}${final_field_name}${sufix}'
|
return '${fn_name}()', true
|
||||||
return '${fn_name}(${obj})', true
|
|
||||||
} else if sym.kind == .chan {
|
} else if sym.kind == .chan {
|
||||||
return '${fn_name}(${deref}it${op}${final_field_name}${sufix})', true
|
return '${fn_name}(${deref}it${op}${final_field_name}${sufix})', true
|
||||||
} else if sym.kind == .thread {
|
} else if sym.kind == .thread {
|
||||||
|
|
3
vlib/v/gen/c/testdata/struct_fn_member_print.c.must_have
vendored
Normal file
3
vlib/v/gen/c/testdata/struct_fn_member_print.c.must_have
vendored
Normal file
|
@ -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();
|
3
vlib/v/gen/c/testdata/struct_fn_member_print.out
vendored
Normal file
3
vlib/v/gen/c/testdata/struct_fn_member_print.out
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
MyStruct{
|
||||||
|
func: fn (int)
|
||||||
|
}
|
18
vlib/v/gen/c/testdata/struct_fn_member_print.vv
vendored
Normal file
18
vlib/v/gen/c/testdata/struct_fn_member_print.vv
vendored
Normal file
|
@ -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}')
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue