mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix alias to struct ptr on structinit (#18571)
This commit is contained in:
parent
b2ca3ac089
commit
83ee2827d4
@ -259,7 +259,8 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string
|
|||||||
if str_method_expects_ptr {
|
if str_method_expects_ptr {
|
||||||
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(&it);')
|
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(&it);')
|
||||||
} else {
|
} else {
|
||||||
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(it);')
|
deref, _ := deref_kind(str_method_expects_ptr, info.parent_type.is_ptr(), info.parent_type)
|
||||||
|
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(${deref}it);')
|
||||||
}
|
}
|
||||||
g.auto_str_funcs.writeln('\tstring res = str_intp(3, _MOV((StrIntpData[]){
|
g.auto_str_funcs.writeln('\tstring res = str_intp(3, _MOV((StrIntpData[]){
|
||||||
{_SLIT0, ${c.si_s_code}, {.d_s = indents }},
|
{_SLIT0, ${c.si_s_code}, {.d_s = indents }},
|
||||||
|
@ -22,7 +22,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
|
|||||||
g.empty_line = false
|
g.empty_line = false
|
||||||
g.write(s)
|
g.write(s)
|
||||||
}
|
}
|
||||||
styp := g.typ(node.typ)
|
styp := g.typ(g.table.unaliased_type(node.typ)).replace('*', '')
|
||||||
mut shared_styp := '' // only needed for shared x := St{...
|
mut shared_styp := '' // only needed for shared x := St{...
|
||||||
if styp in c.skip_struct_init {
|
if styp in c.skip_struct_init {
|
||||||
// needed for c++ compilers
|
// needed for c++ compilers
|
||||||
@ -71,6 +71,10 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
|
|||||||
g.write('{')
|
g.write('{')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// alias to pointer type
|
||||||
|
if g.table.sym(node.typ).kind == .alias && g.table.unaliased_type(node.typ).is_ptr() {
|
||||||
|
g.write('&')
|
||||||
|
}
|
||||||
if is_multiline {
|
if is_multiline {
|
||||||
g.writeln('(${styp}){')
|
g.writeln('(${styp}){')
|
||||||
} else {
|
} else {
|
||||||
|
16
vlib/v/tests/alias_to_ptr_arg_test.v
Normal file
16
vlib/v/tests/alias_to_ptr_arg_test.v
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
struct Foo {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Boo = &Foo
|
||||||
|
|
||||||
|
fn foo(f Boo) {
|
||||||
|
println(f)
|
||||||
|
dump(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
foo(name: '')
|
||||||
|
assert true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user