1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix unreachable code checking for sql ORM blocks (#16948)

This commit is contained in:
Felipe Pena 2023-01-12 10:36:44 -03:00 committed by GitHub
parent 33191e4538
commit ba091a36dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 3 deletions

View File

@ -127,6 +127,7 @@ const (
'vlib/v/tests/orm_sub_array_struct_test.v', 'vlib/v/tests/orm_sub_array_struct_test.v',
'vlib/v/tests/orm_joined_tables_select_test.v', 'vlib/v/tests/orm_joined_tables_select_test.v',
'vlib/v/tests/sql_statement_inside_fn_call_test.v', 'vlib/v/tests/sql_statement_inside_fn_call_test.v',
'vlib/v/tests/orm_stmt_wrong_return_checking_test.v',
'vlib/vweb/tests/vweb_test.v', 'vlib/vweb/tests/vweb_test.v',
'vlib/vweb/csrf/csrf_test.v', 'vlib/vweb/csrf/csrf_test.v',
'vlib/vweb/request_test.v', 'vlib/vweb/request_test.v',
@ -177,6 +178,7 @@ const (
'vlib/v/tests/orm_sub_struct_test.v', 'vlib/v/tests/orm_sub_struct_test.v',
'vlib/v/tests/orm_sub_array_struct_test.v', 'vlib/v/tests/orm_sub_array_struct_test.v',
'vlib/v/tests/orm_joined_tables_select_test.v', 'vlib/v/tests/orm_joined_tables_select_test.v',
'vlib/v/tests/orm_stmt_wrong_return_checking_test.v',
'vlib/v/tests/sql_statement_inside_fn_call_test.v', 'vlib/v/tests/sql_statement_inside_fn_call_test.v',
'vlib/clipboard/clipboard_test.v', 'vlib/clipboard/clipboard_test.v',
'vlib/vweb/tests/vweb_test.v', 'vlib/vweb/tests/vweb_test.v',

View File

@ -128,9 +128,7 @@ fn (mut c Checker) sql_stmt(mut node ast.SqlStmt) ast.Type {
} }
} }
if node.or_expr.kind == .block { if node.or_expr.kind == .block {
for s in node.or_expr.stmts { c.stmts_ending_with_expression(node.or_expr.stmts)
c.stmt(s)
}
} }
return typ return typ
} }

View File

@ -0,0 +1,29 @@
import sqlite
struct Target {
pub mut:
id int [primary; sql: serial]
kind string [nonull]
}
fn add_target(repo Target) !int {
mut dbs := sqlite.connect('test.db')!
defer {
dbs.close() or { panic(err) }
}
sql dbs {
insert repo into Target
} or {
println(err)
return 1
}
assert true
return 1
}
fn test_main() {
add_target(Target{1, 'foo'}) or { println('>> ${err}') }
assert true
}