Skip to content

Commit f80fc37

Browse files
authored
cgen: fix anon struct init passing (fix #24879) (#24884)
1 parent b7b1c2e commit f80fc37

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
31183118
}
31193119
if (exp_sym.kind == .function && !expected_type.has_option_or_result())
31203120
|| (g.inside_struct_init && expected_type == ast.voidptr_type
3121-
&& expected_type != got_type_raw) {
3121+
&& expected_type != got_type_raw && expr !is ast.StructInit) {
31223122
g.write('(voidptr)')
31233123
}
31243124
// no cast
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module main
2+
3+
import json
4+
5+
struct Definition {
6+
version u8
7+
}
8+
9+
struct Logic {
10+
run fn () i8 @[required]
11+
}
12+
13+
fn test_main() {
14+
logic := Logic{
15+
run: fn () i8 {
16+
json.encode_pretty(Definition{})
17+
return 0
18+
}
19+
}
20+
logic.run()
21+
assert true
22+
}

0 commit comments

Comments
 (0)