From 8a176b47b2a746d4cf0899c538672868aae61851 Mon Sep 17 00:00:00 2001 From: Swastik Date: Sun, 5 Jan 2025 00:51:18 +0530 Subject: [PATCH] checker: allow foo(?i64(123)) where param is ?I64 --- vlib/v/checker/check_types.v | 7 ++++++- vlib/v/tests/fn_optional_arg_alias_optional_param_test.v | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/fn_optional_arg_alias_optional_param_test.v diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 8d091dcb4362dd..1f090c3a58fb28 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -282,7 +282,12 @@ fn (mut c Checker) check_expected_call_arg(got_ ast.Type, expected_ ast.Type, la return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } - if !expected.has_flag(.option) && got.has_flag(.option) + is_expected_optional := if is_aliased { + expected_.has_flag(.option) + } else { + expected.has_flag(.option) + } + if !is_expected_optional && got.has_flag(.option) && (!(arg.expr is ast.Ident || arg.expr is ast.ComptimeSelector) || (arg.expr is ast.Ident && c.comptime.get_ct_type_var(arg.expr) != .field_var)) { got_typ_str, expected_typ_str := c.get_string_names_of(got_, expected_) diff --git a/vlib/v/tests/fn_optional_arg_alias_optional_param_test.v b/vlib/v/tests/fn_optional_arg_alias_optional_param_test.v new file mode 100644 index 00000000000000..5b805e444283f6 --- /dev/null +++ b/vlib/v/tests/fn_optional_arg_alias_optional_param_test.v @@ -0,0 +1,8 @@ +type I64 = i64 + +fn test(x ?I64) { +} + +fn test_main() { + test(?i64(123)) +}