From c0f7244654c0154aef64ac5f2be926ca005e83b7 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 18 Sep 2024 06:30:47 +0300 Subject: [PATCH] veb: make implicit context work with custom user types --- vlib/v/checker/fn.v | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 52e356f44be75f..c74df827aa3266 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -436,7 +436,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_idx('veb.Result') if node.return_type == typ_veb_result { - typ_veb_context := ast.Type(u32(c.table.find_type_idx('veb.Context'))).set_nr_muls(1) + // Find a custom user Context type first + mut ctx_idx := c.table.find_type_idx('main.Context') + if ctx_idx < 1 { + // If it doesn't exist, use veb.Context + ctx_idx = c.table.find_type_idx('veb.Context') + } + typ_veb_context := ast.Type(u32(ctx_idx)).set_nr_muls(1) // No `ctx` param? Add it if !node.params.any(it.name == 'ctx') && node.params.len >= 1 { params := node.params.clone()