From 8afdb1c3efc6163704bd9f91773b5403a7065104 Mon Sep 17 00:00:00 2001 From: playX Date: Thu, 5 May 2022 08:23:57 +0000 Subject: [PATCH] checker: c2v: allow passing fixed array as pointer to functions; bool <-> int (#14309) --- vlib/v/checker/check_types.v | 3 +++ vlib/v/checker/fn.v | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 071af72844..7c68e6f3ba 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -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 } diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index bfefab5319..5d4960fa9a 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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`