cgen: fix anon struct init passing (fix #24879) (#24884)

This commit is contained in:
Felipe Pena 2025-07-13 04:17:17 -03:00 committed by GitHub
parent b7b1c2e2e3
commit f80fc37775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -3118,7 +3118,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
}
if (exp_sym.kind == .function && !expected_type.has_option_or_result())
|| (g.inside_struct_init && expected_type == ast.voidptr_type
&& expected_type != got_type_raw) {
&& expected_type != got_type_raw && expr !is ast.StructInit) {
g.write('(voidptr)')
}
// no cast

View File

@ -0,0 +1,22 @@
module main
import json
struct Definition {
version u8
}
struct Logic {
run fn () i8 @[required]
}
fn test_main() {
logic := Logic{
run: fn () i8 {
json.encode_pretty(Definition{})
return 0
}
}
logic.run()
assert true
}