mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
4ba7ad9446
commit
d00237f02c
@ -571,7 +571,7 @@ fn (mut g Gen) fn_decl_params(params []ast.Param, scope &ast.Scope, is_variadic
|
||||
}
|
||||
param_type_sym := g.table.sym(typ)
|
||||
mut param_type_name := g.typ(typ) // util.no_dots(param_type_sym.name)
|
||||
if param_type_sym.kind == .function {
|
||||
if param_type_sym.kind == .function && !typ.has_flag(.option) {
|
||||
info := param_type_sym.info as ast.FnType
|
||||
func := info.func
|
||||
g.write('${g.typ(func.return_type)} (*${caname})(')
|
||||
|
47
vlib/v/tests/option_fn_test.v
Normal file
47
vlib/v/tests/option_fn_test.v
Normal file
@ -0,0 +1,47 @@
|
||||
type HandlerFn = fn ()
|
||||
|
||||
fn new_static_router(route_not_found_handler ?fn ()) fn () {
|
||||
return route_not_found_handler or {
|
||||
fn () {}
|
||||
}
|
||||
}
|
||||
|
||||
fn new_static_router2(route_not_found_handler ?HandlerFn) fn () {
|
||||
return route_not_found_handler or {
|
||||
fn () {}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_option_fn_alias_decl_with_none() {
|
||||
b := new_static_router2(none)
|
||||
$if b is $Function {
|
||||
assert true
|
||||
} $else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
||||
fn test_option_fn_decl_with_none() {
|
||||
a := new_static_router(none)
|
||||
$if a is $Function {
|
||||
assert true
|
||||
} $else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
||||
fn test_option_fn_passing_normal() {
|
||||
anon_1 := fn () {
|
||||
println(1)
|
||||
}
|
||||
c := new_static_router(anon_1)
|
||||
assert c == anon_1
|
||||
}
|
||||
|
||||
fn test_option_fn_passing_to_alias() {
|
||||
anon_2 := fn () {
|
||||
println(2)
|
||||
}
|
||||
d := new_static_router(anon_2)
|
||||
assert d == anon_2
|
||||
}
|
Loading…
Reference in New Issue
Block a user