mirror of
https://github.com/vlang/v.git
synced 2025-09-18 11:56:57 -04:00
checker: fix missing incompatible pushval type for chan <- operator (#21040)
This commit is contained in:
parent
8e9ddb13ea
commit
2798a063fc
@ -705,7 +705,8 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||||||
chan_info := left_sym.chan_info()
|
chan_info := left_sym.chan_info()
|
||||||
elem_type := chan_info.elem_type
|
elem_type := chan_info.elem_type
|
||||||
if !c.check_types(right_type, elem_type) {
|
if !c.check_types(right_type, elem_type) {
|
||||||
c.error('cannot push `${right_sym.name}` on `${left_sym.name}`', right_pos)
|
c.error('cannot push `${c.table.type_to_str(right_type)}` on `${left_sym.name}`',
|
||||||
|
right_pos)
|
||||||
}
|
}
|
||||||
if chan_info.is_mut {
|
if chan_info.is_mut {
|
||||||
// TODO: The error message of the following could be more specific...
|
// TODO: The error message of the following could be more specific...
|
||||||
@ -714,6 +715,9 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||||||
if elem_type.is_ptr() && !right_type.is_ptr() {
|
if elem_type.is_ptr() && !right_type.is_ptr() {
|
||||||
c.error('cannot push non-reference `${right_sym.name}` on `${left_sym.name}`',
|
c.error('cannot push non-reference `${right_sym.name}` on `${left_sym.name}`',
|
||||||
right_pos)
|
right_pos)
|
||||||
|
} else if right_type.is_ptr() != elem_type.is_ptr() {
|
||||||
|
c.error('cannot push `${c.table.type_to_str(right_type)}` on `${left_sym.name}`',
|
||||||
|
right_pos)
|
||||||
}
|
}
|
||||||
c.stmts_ending_with_expression(mut node.or_block.stmts)
|
c.stmts_ending_with_expression(mut node.or_block.stmts)
|
||||||
} else {
|
} else {
|
||||||
|
6
vlib/v/checker/tests/chan_incompatible_type_err.out
Normal file
6
vlib/v/checker/tests/chan_incompatible_type_err.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/chan_incompatible_type_err.vv:6:11: error: cannot push `&Foo` on `chan Foo`
|
||||||
|
4 | ch := chan Foo{}
|
||||||
|
5 | foo := Foo{}
|
||||||
|
6 | ch <- &foo
|
||||||
|
| ^
|
||||||
|
7 | }
|
7
vlib/v/checker/tests/chan_incompatible_type_err.vv
Normal file
7
vlib/v/checker/tests/chan_incompatible_type_err.vv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
struct Foo {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
ch := chan Foo{}
|
||||||
|
foo := Foo{}
|
||||||
|
ch <- &foo
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user