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:
parent
33191e4538
commit
ba091a36dd
@ -127,6 +127,7 @@ const (
|
||||
'vlib/v/tests/orm_sub_array_struct_test.v',
|
||||
'vlib/v/tests/orm_joined_tables_select_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/csrf/csrf_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_array_struct_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/clipboard/clipboard_test.v',
|
||||
'vlib/vweb/tests/vweb_test.v',
|
||||
|
@ -128,9 +128,7 @@ fn (mut c Checker) sql_stmt(mut node ast.SqlStmt) ast.Type {
|
||||
}
|
||||
}
|
||||
if node.or_expr.kind == .block {
|
||||
for s in node.or_expr.stmts {
|
||||
c.stmt(s)
|
||||
}
|
||||
c.stmts_ending_with_expression(node.or_expr.stmts)
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
29
vlib/v/tests/orm_stmt_wrong_return_checking_test.v
Normal file
29
vlib/v/tests/orm_stmt_wrong_return_checking_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user