From 074d5fa7218be9a0dfdeae04858aec21345280a2 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 27 Sep 2024 22:10:33 +0800 Subject: [PATCH] add cast for function argument --- vlib/v/checker/fn.v | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 074f30e25885f7..6e82c43c999498 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -3190,6 +3190,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as } } } + node.args[0].typ = arg_type if method := c.table.find_method(left_sym, method_name) { c.check_expected_call_arg(arg_type, method.params[1].typ, node.language, node.args[0]) or { @@ -3317,8 +3318,10 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as c.ensure_same_array_return_type(mut node, left_type) } else if method_name == 'sorted' { c.ensure_same_array_return_type(mut node, left_type) - } else if method_name == 'sorted_with_compare' { - c.ensure_same_array_return_type(mut node, left_type) + } else if method_name in ['sort_with_compare', 'sorted_with_compare'] { + if method_name == 'sorted_with_compare' { + c.ensure_same_array_return_type(mut node, left_type) + } // Inject a (voidptr) cast for the callback argument, to pass -cstrict, otherwise: // error: incompatible function pointer types passing // 'int (string *, string *)' (aka 'int (struct string *, struct string *)')