mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: c2v: allow passing fixed array as pointer to functions; bool <-> int (#14309)
This commit is contained in:
parent
7499506cf8
commit
8afdb1c3ef
@ -13,6 +13,9 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||
got_is_ptr := got.is_ptr()
|
||||
exp_is_ptr := expected.is_ptr()
|
||||
if c.pref.translated {
|
||||
if expected.is_int() && got.is_int() {
|
||||
return true
|
||||
}
|
||||
if expected == ast.byteptr_type {
|
||||
return true
|
||||
}
|
||||
|
@ -935,6 +935,12 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||
if arg_typ == ast.int_type && param_typ_sym.kind == .enum_ {
|
||||
continue
|
||||
}
|
||||
|
||||
if (arg_typ == ast.bool_type && param.typ.is_int())
|
||||
|| (arg_typ.is_int() && param.typ == ast.bool_type) {
|
||||
continue
|
||||
}
|
||||
|
||||
// In C unsafe number casts are used all the time (e.g. `char*` where
|
||||
// `int*` is expected etc), so just allow them all.
|
||||
mut param_is_number := param.typ.is_number()
|
||||
@ -953,8 +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_sym.kind == .array_fixed && typ_is_number) {
|
||||
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())) {
|
||||
continue
|
||||
}
|
||||
// Allow `int` as `&i8`
|
||||
|
Loading…
Reference in New Issue
Block a user