1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix result of typeof function returns result type (#17849)

This commit is contained in:
ChAoS_UnItY 2023-04-02 08:25:34 +08:00 committed by GitHub
parent 51ad565ed6
commit c7237b1c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -479,6 +479,8 @@ fn (mut g Gen) fn_decl_str(info ast.FnType) string {
x := util.strip_main_name(g.table.get_type_name(g.unwrap_generic(info.func.return_type)))
if info.func.return_type.has_flag(.option) {
fn_str += ' ?${x}'
} else if info.func.return_type.has_flag(.result) {
fn_str += ' !${x}'
} else {
fn_str += ' ${x}'
}

View File

@ -1,5 +1,7 @@
fn test_typeof_fn() {
assert typeof[fn (s string, x u32) (int, f32)]().name == 'fn (string, u32) (int, f32)'
assert typeof[fn (s string, x u32) ?(int, f32)]().name == 'fn (string, u32) ?(int, f32)'
assert typeof[fn (s string, x u32) !(int, f32)]().name == 'fn (string, u32) !(int, f32)'
}
fn test_typeof_int() {