Skip to content

Commit

Permalink
checker: allow calling foo(?i64(123)) for fn foo(x ?I64) { and `t…
Browse files Browse the repository at this point in the history
…ype I64 = i64` (#23373)
  • Loading branch information
Delta456 authored Jan 5, 2025
1 parent 43d679b commit af1ef92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vlib/v/checker/check_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
8 changes: 8 additions & 0 deletions vlib/v/tests/fn_optional_arg_alias_optional_param_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type I64 = i64

fn test(x ?I64) {
}

fn test_main() {
test(?i64(123))
}

0 comments on commit af1ef92

Please sign in to comment.