From 0056d557b686cf37054832714858edb7197c8347 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Fri, 28 Mar 2025 18:43:49 +0800 Subject: [PATCH] markused: support orm or expr (fix #24040) (#24059) --- cmd/tools/vtest-self.v | 4 ++++ vlib/v/markused/walker.v | 2 ++ vlib/v/tests/orm_or_test.v | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 vlib/v/tests/orm_or_test.v diff --git a/cmd/tools/vtest-self.v b/cmd/tools/vtest-self.v index 278be5d7d..1e8551981 100644 --- a/cmd/tools/vtest-self.v +++ b/cmd/tools/vtest-self.v @@ -171,6 +171,7 @@ const skip_with_fsanitize_memory = [ 'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v', 'vlib/v/tests/orm_create_several_tables_test.v', 'vlib/v/tests/orm_update_test.v', + 'vlib/v/tests/orm_or_test.v', 'vlib/vweb/tests/vweb_test.v', 'vlib/vweb/csrf/csrf_test.v', 'vlib/net/http/request_test.v', @@ -196,6 +197,7 @@ const skip_with_fsanitize_address = [ 'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v', 'vlib/v/tests/orm_create_several_tables_test.v', 'vlib/v/tests/orm_update_test.v', + 'vlib/v/tests/orm_or_test.v', ] const skip_with_fsanitize_undefined = [ 'do_not_remove', @@ -209,6 +211,7 @@ const skip_with_fsanitize_undefined = [ 'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v', 'vlib/v/tests/orm_create_several_tables_test.v', 'vlib/v/tests/orm_update_test.v', + 'vlib/v/tests/orm_or_test.v', 'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v', // fails compilation with: undefined reference to vtable for __cxxabiv1::__function_type_info' ] const skip_on_ubuntu_musl = [ @@ -251,6 +254,7 @@ const skip_on_ubuntu_musl = [ 'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v', 'vlib/v/tests/orm_create_several_tables_test.v', 'vlib/v/tests/orm_update_test.v', + 'vlib/v/tests/orm_or_test.v', 'vlib/v/tests/sql_statement_inside_fn_call_test.v', 'vlib/v/tests/websocket_logger_interface_should_compile_test.v', 'vlib/v/tests/fns/fn_literal_type_test.v', diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index ae076e909..9f2455f41 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -251,6 +251,7 @@ pub fn (mut w Walker) stmt(node_ ast.Stmt) { } ast.SqlStmt { w.expr(node.db_expr) + w.expr(node.or_expr) for line in node.lines { w.expr(line.where_expr) w.exprs(line.update_exprs) @@ -522,6 +523,7 @@ fn (mut w Walker) expr(node_ ast.Expr) { } ast.SqlExpr { w.expr(node.db_expr) + w.expr(node.or_expr) w.expr(node.offset_expr) w.expr(node.order_expr) w.expr(node.limit_expr) diff --git a/vlib/v/tests/orm_or_test.v b/vlib/v/tests/orm_or_test.v new file mode 100644 index 000000000..6818beaa3 --- /dev/null +++ b/vlib/v/tests/orm_or_test.v @@ -0,0 +1,24 @@ +import db.sqlite +import math + +struct Counter { + id int @[primary; sql: serial] + f f64 +} + +fn test_orm_or_block() { + db := sqlite.connect(':memory:') or { panic(err) } + + sql db { + drop table Counter + } or { println(math.e) } // this should compile + + x := sql db { + select from Counter + } or { + [Counter{ + f: math.pi + }] + } + assert x[0].f == math.pi +} -- 2.39.5