Skip to content

Commit

Permalink
checker: allow none to be passed to ?T param (fix #23381) (#23385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 authored Jan 6, 2025
1 parent 8ec8cf0 commit 2aa5651
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
}
}
arg_typ_sym := c.table.sym(arg_typ)
if arg_typ_sym.kind == .none && param.typ.has_flag(.generic) {
if arg_typ_sym.kind == .none && param.typ.has_flag(.generic) && !param.typ.has_flag(.option) {
c.error('cannot use `none` as generic argument', call_arg.pos)
}
param_typ_sym := c.table.sym(param.typ)
Expand Down Expand Up @@ -2546,7 +2546,8 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool)
}
continue
}
if final_arg_sym.kind == .none && param.typ.has_flag(.generic) {
if final_arg_sym.kind == .none && param.typ.has_flag(.generic)
&& !param.typ.has_flag(.option) {
c.error('cannot use `none` as generic argument', arg.pos)
}
if param.typ.is_ptr() && !arg.typ.is_any_kind_of_pointer() && arg.expr.is_literal()
Expand Down
6 changes: 6 additions & 0 deletions vlib/v/tests/fn_generic_option_none_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn test[T](x T, b ?T) {
}

fn test_main() {
test[int](123, none)
}

0 comments on commit 2aa5651

Please sign in to comment.