diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 71929f4841..2ec3a7bcfd 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5722,7 +5722,7 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) { has_unwrap_opt_res) } else { g.const_decl_init_later(field.mod, name, field.expr, field.typ, false, - false) + true) } } } diff --git a/vlib/v/tests/modules/consts_with_complex_init/config.v b/vlib/v/tests/modules/consts_with_complex_init/config.v new file mode 100644 index 0000000000..44e8c9e352 --- /dev/null +++ b/vlib/v/tests/modules/consts_with_complex_init/config.v @@ -0,0 +1,13 @@ +module main + +import rand + +struct MyStruct { + foo int +} + +const my_struct = MyStruct{rand.intn(6) or { panic(err) }} + +fn main() { + dump('hello') +} diff --git a/vlib/v/tests/modules/consts_with_complex_init/consts_should_not_conflict_test.v b/vlib/v/tests/modules/consts_with_complex_init/consts_should_not_conflict_test.v new file mode 100644 index 0000000000..06571ced31 --- /dev/null +++ b/vlib/v/tests/modules/consts_with_complex_init/consts_should_not_conflict_test.v @@ -0,0 +1,9 @@ +module main + +import os + +const cfg_dir = os.join_path(os.config_dir() or { panic(err) }, 'foo') + +fn test_main() { + dump('hello') +}