checker: c2v fixes (#14332)

playX 2022-05-07 06:50:41 +00:00 committed by Jef Roosens
parent cb52c68a62
commit 1e83e10119
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 15 additions and 8 deletions

View File

@ -22,7 +22,8 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
if expected == ast.voidptr_type {
return true
}
if expected == ast.bool_type && (got.is_any_kind_of_pointer() || got.is_int()) {
if (expected == ast.bool_type && (got.is_any_kind_of_pointer() || got.is_int()))
|| ((expected.is_any_kind_of_pointer() || expected.is_int()) && got == ast.bool_type) {
return true
}
@ -50,9 +51,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
}
} else if got_sym.kind == .array_fixed {
// Allow fixed arrays as `&i8` etc
if expected_sym.is_number() {
return true
} else if expected.is_any_kind_of_pointer() {
if expected_sym.is_number() || expected.is_any_kind_of_pointer() {
return true
}
} else if expected_sym.kind == .array_fixed {
@ -65,6 +64,14 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return true
}
}
} else if got_sym.kind == .array {
if expected_sym.is_number() || expected.is_any_kind_of_pointer() {
return true
}
} else if expected_sym.kind == .array {
if got_sym.is_number() && got.is_any_kind_of_pointer() {
return true
}
}
if expected_sym.kind == .enum_ && got_sym.is_number() {
// Allow enums as numbers

View File

@ -959,10 +959,10 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
continue
}
// Allow `[32]i8` as `&i8` etc
if (arg_typ_sym.kind == .array_fixed && (param_is_number
|| param.typ.is_any_kind_of_pointer()))
|| (param_typ_sym.kind == .array_fixed && (typ_is_number
|| arg_typ.is_any_kind_of_pointer())) {
if ((arg_typ_sym.kind == .array_fixed || arg_typ_sym.kind == .array)
&& (param_is_number || param.typ.is_any_kind_of_pointer()))
|| ((param_typ_sym.kind == .array_fixed || param_typ_sym.kind == .array)
&& (typ_is_number || arg_typ.is_any_kind_of_pointer())) {
continue
}
// Allow `int` as `&i8`