From 1e83e10119580dfccd01306efd1597c3416b5ba1 Mon Sep 17 00:00:00 2001 From: playX Date: Sat, 7 May 2022 06:50:41 +0000 Subject: [PATCH] checker: c2v fixes (#14332) --- vlib/v/checker/check_types.v | 15 +++++++++++---- vlib/v/checker/fn.v | 8 ++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 7c68e6f3ba..4ff9813805 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -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 diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 42eea161b3..25783c61b2 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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`