Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 25, 2024
1 parent 5c08dc1 commit 2c5130f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vlib/v/gen/c/spawn_and_go.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
mut handle := ''
tmp := g.new_tmp_var()
mut expr := node.call_expr
mut name := '${expr.name}_${expr.pos.pos}'
mut name := expr.name
mut use_tmp_fn_var := false
tmp_fn := g.new_tmp_var()

if expr.is_fn_var {
// generate a name different for same var fn name declared in another scope
name = '${name}_${node.pos.pos}'
}

if expr.concrete_types.len > 0 {
name = g.generic_fn_name(expr.concrete_types, name)
} else if expr.is_fn_var && expr.fn_var_type.has_flag(.generic) {
Expand Down
24 changes: 24 additions & 0 deletions vlib/v/tests/chan_same_fn_name_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
fn a() chan string {
ch_out := chan string{}
f := fn (a chan string) {
a <- 'foo'
}
spawn f(ch_out)
return ch_out
}

fn b(ch_in chan string) string {
f := fn (a chan string, b chan string) {
val := <-a
{}
b <- val
}
ch_out := chan string{}
spawn f(ch_in, ch_out)
return <-ch_out
}

fn test_main() {
ch0 := a()
assert b(ch0) == 'foo'
}

0 comments on commit 2c5130f

Please sign in to comment.