checker: fix calls with result propagation, using other consts, in const declaration expressions (fix #21609) (#25060)

This commit is contained in:
Krchi 2025-08-07 22:22:31 +08:00 committed by GitHub
parent 3b561d590d
commit 3a6b651fa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -4256,9 +4256,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
if typ == 0 { if typ == 0 {
old_c_mod := c.mod old_c_mod := c.mod
c.mod = obj.mod c.mod = obj.mod
inside_const := c.inside_const
c.inside_const = true c.inside_const = true
typ = c.expr(mut obj.expr) typ = c.expr(mut obj.expr)
c.inside_const = false c.inside_const = inside_const
c.mod = old_c_mod c.mod = old_c_mod
if mut obj.expr is ast.CallExpr { if mut obj.expr is ast.CallExpr {

View file

@ -0,0 +1,10 @@
const constant = 5
const other = init_const(constant)!
fn test_main() {
assert other == 5
}
fn init_const(c int) !int {
return c
}