1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: simplify checking array append type mismatch (#10422)

This commit is contained in:
yuyi 2021-06-13 11:29:40 +08:00 committed by GitHub
parent a6eba7a9b4
commit cab054c1ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 15 deletions

View File

@ -331,13 +331,6 @@ 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

View File

@ -1235,14 +1235,9 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
return ast.void_type
}
// the expressions have different types (array_x and x)
if c.check_types(right_type, left_value_type) { // , right_type) {
// []T << T
return ast.void_type
}
if right_final.kind == .array
&& c.check_array_value_types(left_value_type, c.table.value_type(right_type)) {
// []T << []T
// []T << T or []T << []T
if c.check_types(right_type, left_value_type)
|| c.check_types(right_type, left_type) {
return ast.void_type
}
c.error('cannot append `$right_sym.name` to `$left_sym.name`', right_pos)