mirror of
https://github.com/vlang/v.git
synced 2025-09-17 03:17:25 -04:00
cgen: fix missing scope enclosing for const init which needs temp variables (#20973)
This commit is contained in:
parent
83978a8d86
commit
679bcb3094
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
vlib/v/tests/modules/consts_with_complex_init/config.v
Normal file
13
vlib/v/tests/modules/consts_with_complex_init/config.v
Normal file
@ -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')
|
||||
}
|
@ -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')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user