From 3a6b651fa4d275bc0f026f63ea101b5cf2abea6c Mon Sep 17 00:00:00 2001 From: Krchi <997054144@qq.com> Date: Thu, 7 Aug 2025 22:22:31 +0800 Subject: [PATCH] checker: fix calls with result propagation, using other consts, in const declaration expressions (fix #21609) (#25060) --- vlib/v/checker/checker.v | 3 ++- vlib/v/tests/consts/const_propagate_result_test.v | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/consts/const_propagate_result_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 9ec2f4f804..380edbff32 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4256,9 +4256,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type { if typ == 0 { old_c_mod := c.mod c.mod = obj.mod + inside_const := c.inside_const c.inside_const = true typ = c.expr(mut obj.expr) - c.inside_const = false + c.inside_const = inside_const c.mod = old_c_mod if mut obj.expr is ast.CallExpr { diff --git a/vlib/v/tests/consts/const_propagate_result_test.v b/vlib/v/tests/consts/const_propagate_result_test.v new file mode 100644 index 0000000000..58170c9312 --- /dev/null +++ b/vlib/v/tests/consts/const_propagate_result_test.v @@ -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 +}