From 64e81258078f840da25187a4689b644adae1cefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Thu, 13 Aug 2020 20:06:56 +0200 Subject: [PATCH] cgen: fixe calling anon fn asynchronously (closes #6088) (#6121) --- vlib/v/gen/cgen.v | 4 ++++ vlib/v/tests/anon_fn_test.v | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 vlib/v/tests/anon_fn_test.v diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index eab989a0ab..da663b5fd9 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -4352,6 +4352,10 @@ fn (mut g Gen) go_stmt(node ast.GoStmt) { if expr.is_method { receiver_sym := g.table.get_type_symbol(expr.receiver_type) name = receiver_sym.name + '_' + name + } else if expr.left is ast.AnonFn as anon_fn { + g.gen_anon_fn_decl(anon_fn) + fsym := g.table.get_type_symbol(anon_fn.typ) + name = fsym.name } name = util.no_dots(name) g.writeln('// go') diff --git a/vlib/v/tests/anon_fn_test.v b/vlib/v/tests/anon_fn_test.v new file mode 100644 index 0000000000..0773e4cccf --- /dev/null +++ b/vlib/v/tests/anon_fn_test.v @@ -0,0 +1,9 @@ +import sync + +fn test_go_anon_fn() { + mut wg := sync.new_waitgroup() + go fn (mut wg sync.WaitGroup) { + wg.done() + }(mut wg) + wg.wait() +}