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

cgen: fix missing * of optional non-ref structs (fix: #16070) (#16071)

This commit is contained in:
shove 2022-10-14 15:34:42 +08:00 committed by GitHub
parent 39d2aa71df
commit 6bf2ad1ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1036,7 +1036,7 @@ fn (g Gen) optional_type_text(styp string, base string) string {
} else if base.starts_with('anon_fn') {
'void*'
} else {
base
if base.starts_with('struct ') && !base.ends_with('*') { '$base*' } else { base }
}
ret := 'struct $styp {
byte state;
@ -1053,7 +1053,7 @@ fn (g Gen) result_type_text(styp string, base string) string {
} else if base.starts_with('anon_fn') {
'void*'
} else {
base
if base.starts_with('struct ') && !base.ends_with('*') { '$base*' } else { base }
}
ret := 'struct $styp {
bool is_error;

View File

@ -390,6 +390,15 @@ fn test_optional_ref_c_struct_gen() {
_ := get_opt_pointer_to_c_struct() or { &C.stat{} }
}
// For issue #16070: cgen error: missing * of optional non-ref structs
fn get_opt_to_c_struct() ?C.stat {
return none
}
fn test_optional_c_struct_gen() {
_ := get_opt_to_c_struct() or { C.stat{} }
}
// For issue #16062: checker disallow the return of voidptr(nil) in or block
struct Bar {}