cgen: fix auto str for fn struct member (#21825)

This commit is contained in:
Felipe Pena 2024-07-09 15:08:31 -03:00 committed by GitHub
parent 70e78cc766
commit 494be20564
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 2 deletions

View file

@ -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 {

View 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();

View file

@ -0,0 +1,3 @@
MyStruct{
func: fn (int)
}

View 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}')
}