cgen: fix missing scope enclosing for const init which needs temp variables (#20973)

This commit is contained in:
Felipe Pena 2024-03-08 15:16:02 -03:00 committed by GitHub
parent 83978a8d86
commit 679bcb3094
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View File

@ -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)
}
}
}

View 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')
}

View File

@ -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')
}