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

pull/10444/head
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 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) ? { pub fn (mut c Checker) check_expected(got ast.Type, expected ast.Type) ? {
if c.check_types(got, expected) { if c.check_types(got, expected) {
return return

View File

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