cgen: fix anon_fn_call (#8120)
parent
0da40c4ea9
commit
0945efebf1
|
@ -93,6 +93,7 @@ mut:
|
||||||
map_fn_definitions []string // map equality functions that have been defined
|
map_fn_definitions []string // map equality functions that have been defined
|
||||||
struct_fn_definitions []string // struct equality functions that have been defined
|
struct_fn_definitions []string // struct equality functions that have been defined
|
||||||
auto_fn_definitions []string // auto generated functions defination list
|
auto_fn_definitions []string // auto generated functions defination list
|
||||||
|
anon_fn_definitions []string // anon generated functions defination list
|
||||||
is_json_fn bool // inside json.encode()
|
is_json_fn bool // inside json.encode()
|
||||||
json_types []string // to avoid json gen duplicates
|
json_types []string // to avoid json gen duplicates
|
||||||
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
|
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
|
||||||
|
@ -341,6 +342,11 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
||||||
b.writeln(fn_def)
|
b.writeln(fn_def)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if g.anon_fn_definitions.len > 0 {
|
||||||
|
for fn_def in g.anon_fn_definitions {
|
||||||
|
b.writeln(fn_def)
|
||||||
|
}
|
||||||
|
}
|
||||||
b.writeln('\n// V out')
|
b.writeln('\n// V out')
|
||||||
b.write(g.out.str())
|
b.write(g.out.str())
|
||||||
b.writeln('\n// THE END.')
|
b.writeln('\n// THE END.')
|
||||||
|
@ -2361,12 +2367,10 @@ fn (mut g Gen) autofree_var_call(free_fn_name string, v ast.Var) {
|
||||||
|
|
||||||
fn (mut g Gen) gen_anon_fn_decl(it ast.AnonFn) {
|
fn (mut g Gen) gen_anon_fn_decl(it ast.AnonFn) {
|
||||||
pos := g.out.len
|
pos := g.out.len
|
||||||
def_pos := g.definitions.len
|
|
||||||
g.stmt(it.decl)
|
g.stmt(it.decl)
|
||||||
fn_body := g.out.after(pos)
|
fn_body := g.out.after(pos)
|
||||||
g.out.go_back(fn_body.len)
|
g.out.go_back(fn_body.len)
|
||||||
g.definitions.go_back(g.definitions.len - def_pos)
|
g.anon_fn_definitions << fn_body
|
||||||
g.definitions.write(fn_body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) map_fn_ptrs(key_typ table.TypeSymbol) (string, string, string, string) {
|
fn (mut g Gen) map_fn_ptrs(key_typ table.TypeSymbol) (string, string, string, string) {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
fn test_anon_fn_call() {
|
||||||
|
anon_fn := fn() string {
|
||||||
|
return test()
|
||||||
|
}
|
||||||
|
assert anon_fn() == 'Test'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test() string {
|
||||||
|
return "Test"
|
||||||
|
}
|
Loading…
Reference in New Issue