From 55688c3d8e3e4a95bb8c3f4f3ff0d02e024fa36a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 10:25:05 +0300 Subject: [PATCH] orm: fix C compilation error (fixes #26224) --- vlib/v/checker/infix.v | 4 +++- .../orm_update_anon_fn_option_infix_err.out | 7 ++++++ .../orm_update_anon_fn_option_infix_err.vv | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.out create mode 100644 vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.vv diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index 638adaf0a..c00ab4cba 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -1133,7 +1133,9 @@ fn (mut c Checker) check_sort_external_variable_access(node ast.Expr) bool { } fn (mut c Checker) check_option_infix_expr(node ast.InfixExpr, left_type ast.Type, right_type ast.Type, left_sym ast.TypeSymbol, right_sym ast.TypeSymbol) { - if c.inside_sql { + // SQL expressions can compare optional values directly, but anon fn bodies in SQL + // should keep regular option checks. + if c.inside_sql && !c.inside_anon_fn { return } left_is_option := left_type.has_flag(.option) diff --git a/vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.out b/vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.out new file mode 100644 index 000000000..56de2e84d --- /dev/null +++ b/vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.vv:19:17: error: `?string` cannot be used as `string`, unwrap the option first + 17 | sql db { + 18 | update User set email = fn [req] () string { + 19 | return if req.email != '' { 'nickname_1' } else { 'nickname_0' } + | ~~~~~ + 20 | }() where id == '1' + 21 | }! diff --git a/vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.vv b/vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.vv new file mode 100644 index 000000000..ab2f83acf --- /dev/null +++ b/vlib/v/checker/tests/orm_update_anon_fn_option_infix_err.vv @@ -0,0 +1,22 @@ +import db.sqlite + +struct User { + id string @[primary] + email ?string +} + +struct UserReq { + email ?string +} + +fn main() { + mut db := sqlite.connect(':memory:')! + req := UserReq{ + email: 'admin@admin.com' + } + sql db { + update User set email = fn [req] () string { + return if req.email != '' { 'nickname_1' } else { 'nickname_0' } + }() where id == '1' + }! +} -- 2.39.5