Skip to content

Commit 3a6b651

Browse files
authored
checker: fix calls with result propagation, using other consts, in const declaration expressions (fix #21609) (#25060)
1 parent 3b561d5 commit 3a6b651

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎vlib/v/checker/checker.v‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4256,9 +4256,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
42564256
if typ == 0 {
42574257
old_c_mod := c.mod
42584258
c.mod = obj.mod
4259+
inside_const := c.inside_const
42594260
c.inside_const = true
42604261
typ = c.expr(mut obj.expr)
4261-
c.inside_const = false
4262+
c.inside_const = inside_const
42624263
c.mod = old_c_mod
42634264

42644265
if mut obj.expr is ast.CallExpr {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const constant = 5
2+
const other = init_const(constant)!
3+
4+
fn test_main() {
5+
assert other == 5
6+
}
7+
8+
fn init_const(c int) !int {
9+
return c
10+
}

0 commit comments

Comments
 (0)