From df8cb3e94c63c266d6388b57f7a0dcea9f087f42 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 25 Mar 2026 16:42:16 +0300 Subject: [PATCH] checker: fix veb c compilation error when context not mutable (fixes #25361) --- vlib/v/checker/fn.v | 7 +++++++ .../checker/tests/veb_context_param_mutability.out | 7 +++++++ .../v/checker/tests/veb_context_param_mutability.vv | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 vlib/v/checker/tests/veb_context_param_mutability.out create mode 100644 vlib/v/checker/tests/veb_context_param_mutability.vv diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 7d67d0f84..1646f5789 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -788,6 +788,13 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { // Register implicit context var typ_veb_result := c.table.get_veb_result_type_idx() // c.table.find_type('veb.Result') if node.is_method && node.return_type == typ_veb_result { + for param in node.params[1..] { + if c.has_veb_context(param.typ) && !param.is_mut { + c.error('veb app method `${node.name}` must declare context parameter `${param.name}` as mutable, e.g. `mut ${param.name} ${c.table.type_to_str(param.typ)}`', + param.pos) + break + } + } // Find a custom user Context type first mut ctx_idx := c.table.find_type('main.Context') if ctx_idx < 1 { diff --git a/vlib/v/checker/tests/veb_context_param_mutability.out b/vlib/v/checker/tests/veb_context_param_mutability.out new file mode 100644 index 000000000..3f6c8cf8a --- /dev/null +++ b/vlib/v/checker/tests/veb_context_param_mutability.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/veb_context_param_mutability.vv:11:25: error: veb app method `index` must declare context parameter `ctx` as mutable, e.g. `mut ctx Context` + 9 | pub struct App {} + 10 | + 11 | pub fn (app &App) index(ctx Context) veb.Result { + | ~~~ + 12 | return veb.no_result() + 13 | } diff --git a/vlib/v/checker/tests/veb_context_param_mutability.vv b/vlib/v/checker/tests/veb_context_param_mutability.vv new file mode 100644 index 000000000..4f8955b9b --- /dev/null +++ b/vlib/v/checker/tests/veb_context_param_mutability.vv @@ -0,0 +1,13 @@ +module main + +import veb + +pub struct Context { + veb.Context +} + +pub struct App {} + +pub fn (app &App) index(ctx Context) veb.Result { + return veb.no_result() +} -- 2.39.5