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

cgen: remove spaces in the generated name for ?&C.struct (fix #16058) (#16059)

This commit is contained in:
shove 2022-10-13 23:05:16 +08:00 committed by GitHub
parent bfbfe78366
commit e3e8bb2f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -1001,7 +1001,13 @@ fn (mut g Gen) expr_string_surround(prepend string, expr ast.Expr, append string
// if one location changes
fn (mut g Gen) optional_type_name(t ast.Type) (string, string) {
base := g.base_type(t)
mut styp := '_option_$base'
mut styp := ''
sym := g.table.sym(t)
if sym.language == .c && sym.kind == .struct_ {
styp = '${c.option_name}_${base.replace(' ', '_')}'
} else {
styp = '${c.option_name}_$base'
}
if t.is_ptr() {
styp = styp.replace('*', '_ptr')
}
@ -1010,7 +1016,13 @@ fn (mut g Gen) optional_type_name(t ast.Type) (string, string) {
fn (mut g Gen) result_type_name(t ast.Type) (string, string) {
base := g.base_type(t)
mut styp := '${c.result_name}_$base'
mut styp := ''
sym := g.table.sym(t)
if sym.language == .c && sym.kind == .struct_ {
styp = '${c.result_name}_${base.replace(' ', '_')}'
} else {
styp = '${c.result_name}_$base'
}
if t.is_ptr() {
styp = styp.replace('*', '_ptr')
}

View File

@ -380,3 +380,13 @@ fn test_return_or() {
x := foo2() or { return }
assert x == 0
}
// For issue #16058: cgen error: exists spaces in the name of the ?&C.struct
fn bar() ?&C.stat {
return none
}
fn test_optional_ref_c_struct_gen() {
_ := bar() or { &C.stat{} }
assert true
}