mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check array type mismatch of array append (#10405)
This commit is contained in:
parent
9d852e22b2
commit
7878bad95e
@ -331,6 +331,13 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
fn (mut c Checker) check_array_value_types(got ast.Type, expected ast.Type) bool {
|
||||
if expected.is_number() && got.is_number() && expected != c.table.mktyp(got) {
|
||||
return false
|
||||
}
|
||||
return c.check_types(got, expected)
|
||||
}
|
||||
|
||||
pub fn (mut c Checker) check_expected(got ast.Type, expected ast.Type) ? {
|
||||
if c.check_types(got, expected) {
|
||||
return
|
||||
|
@ -1242,7 +1242,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||
return ast.void_type
|
||||
}
|
||||
if right_final.kind == .array
|
||||
&& c.check_types(left_value_type, c.table.value_type(right_type)) {
|
||||
&& c.check_array_value_types(left_value_type, c.table.value_type(right_type)) {
|
||||
// []T << []T
|
||||
return ast.void_type
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/array_append_array_type_mismatch_err.vv:3:8: error: cannot append `[]int` to `[]byte`
|
||||
1 | fn main() {
|
||||
2 | mut bc := []byte{}
|
||||
3 | bc << [0xCA, 0xFE, 0xBA, 0xBE]
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
4 | println(bc)
|
||||
5 | }
|
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
mut bc := []byte{}
|
||||
bc << [0xCA, 0xFE, 0xBA, 0xBE]
|
||||
println(bc)
|
||||
}
|
Loading…
Reference in New Issue
Block a user