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

cgen: fix missing type name when anonymous struct is used as parameter. fix #15698 (#15699)

This commit is contained in:
shove
2022-09-10 14:35:42 +08:00
committed by GitHub
parent b429aad63b
commit bce1039c9c
2 changed files with 12 additions and 2 deletions

View File

@@ -49,8 +49,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
}
}
if is_anon {
// No name needed for anon structs, C figures it out on its own.
g.writeln('{')
g.writeln('($styp){')
} else if g.is_shared && !g.inside_opt_data && !g.is_arraymap_set {
mut shared_typ := node.typ.set_flag(.shared_f)
shared_styp = g.typ(shared_typ)

View File

@@ -0,0 +1,11 @@
module main
fn func(arg struct { foo string }) {
assert arg.foo == 'foo'
}
fn test_anon_struct_as_parameter() {
func(struct {
foo: 'foo'
})
}