Skip to content

Commit bce1039

Browse files
authored
cgen: fix missing type name when anonymous struct is used as parameter. fix #15698 (#15699)
1 parent b429aad commit bce1039

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

vlib/v/gen/c/struct.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
4949
}
5050
}
5151
if is_anon {
52-
// No name needed for anon structs, C figures it out on its own.
53-
g.writeln('{')
52+
g.writeln('($styp){')
5453
} else if g.is_shared && !g.inside_opt_data && !g.is_arraymap_set {
5554
mut shared_typ := node.typ.set_flag(.shared_f)
5655
shared_styp = g.typ(shared_typ)

vlib/v/tests/anon_struct_type_test.v

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main
2+
3+
fn func(arg struct { foo string }) {
4+
assert arg.foo == 'foo'
5+
}
6+
7+
fn test_anon_struct_as_parameter() {
8+
func(struct {
9+
foo: 'foo'
10+
})
11+
}

0 commit comments

Comments
 (0)