Skip to content

Commit

Permalink
checker: fix pushing enum value to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Dec 23, 2024
1 parent f5445b5 commit 6440036
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
c.expected_type = former_expected_type
}
mut left_type := c.expr(mut node.left)
mut left_sym := c.table.sym(left_type)
node.left_type = left_type
c.expected_type = left_type

if left_sym.kind == .chan {
chan_info := left_sym.chan_info()
c.expected_type = chan_info.elem_type
}

// `if n is ast.Ident && n.is_mut { ... }`
if !c.inside_sql && node.op == .and {
mut left_node := node.left
Expand Down Expand Up @@ -103,7 +109,6 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
mut right_sym := c.table.sym(right_type)
right_final_sym := c.table.final_sym(right_type)
mut left_sym := c.table.sym(left_type)
left_final_sym := c.table.final_sym(left_type)
left_pos := node.left.pos()
right_pos := node.right.pos()
Expand Down
11 changes: 11 additions & 0 deletions vlib/v/tests/concurrency/chan_push_enum_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum FooBar {
foo
bar
}

fn test_chan_push_enum() {
ch := chan FooBar{cap: 10}
ch <- .foo
println(<-ch)
assert true
}

0 comments on commit 6440036

Please sign in to comment.