mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
bfbfe78366
commit
e3e8bb2f88
@ -1001,7 +1001,13 @@ fn (mut g Gen) expr_string_surround(prepend string, expr ast.Expr, append string
|
|||||||
// if one location changes
|
// if one location changes
|
||||||
fn (mut g Gen) optional_type_name(t ast.Type) (string, string) {
|
fn (mut g Gen) optional_type_name(t ast.Type) (string, string) {
|
||||||
base := g.base_type(t)
|
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() {
|
if t.is_ptr() {
|
||||||
styp = styp.replace('*', '_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) {
|
fn (mut g Gen) result_type_name(t ast.Type) (string, string) {
|
||||||
base := g.base_type(t)
|
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() {
|
if t.is_ptr() {
|
||||||
styp = styp.replace('*', '_ptr')
|
styp = styp.replace('*', '_ptr')
|
||||||
}
|
}
|
||||||
|
@ -380,3 +380,13 @@ fn test_return_or() {
|
|||||||
x := foo2() or { return }
|
x := foo2() or { return }
|
||||||
assert x == 0
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user