diff --git a/vlib/orm/orm_null_test.v b/vlib/orm/orm_null_test.v index 27dec5ed07d2dd..253de0f60af721 100644 --- a/vlib/orm/orm_null_test.v +++ b/vlib/orm/orm_null_test.v @@ -227,10 +227,10 @@ struct Bar { age int } -fn update_bar1(db MockDB, id u64, name ?string) ! { +fn update_bar1(db MockDB, id u64, name_ ?string) ! { foo := 66 sql db { - update Bar set name = name, age = age + 3 + foo where id == id + update Bar set name = name_, age = age + 3 + foo where id == id }! } diff --git a/vlib/v/checker/orm.v b/vlib/v/checker/orm.v index 19ed2a349d90e9..c9bbf80773dfdd 100644 --- a/vlib/v/checker/orm.v +++ b/vlib/v/checker/orm.v @@ -338,6 +338,13 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type { field := node.fields.filter(it.name == column)[0] c.expected_type = field.typ } + if mut expr is ast.Ident { + for field in fields { + if expr.name == field.name { + c.error('unknown V identifier `${field.name}`', expr.pos) + } + } + } c.expr(mut expr) } } diff --git a/vlib/v/checker/tests/orm_update_right_type_ident_err.out b/vlib/v/checker/tests/orm_update_right_type_ident_err.out new file mode 100644 index 00000000000000..f23a937b223d6b --- /dev/null +++ b/vlib/v/checker/tests/orm_update_right_type_ident_err.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/orm_update_right_type_ident_err.vv:16:38: error: unknown V identifier `seo_f1` + 14 | + 15 | sql db { + 16 | update SeoBlock set seo_f1 = seo_f1 where seo_f1 == "" + | ~~~~~~ + 17 | } or { panic(err) } + 18 | } diff --git a/vlib/v/checker/tests/orm_update_right_type_ident_err.vv b/vlib/v/checker/tests/orm_update_right_type_ident_err.vv new file mode 100644 index 00000000000000..ea47056723f5f0 --- /dev/null +++ b/vlib/v/checker/tests/orm_update_right_type_ident_err.vv @@ -0,0 +1,18 @@ +module main + +import db.sqlite + +pub struct SeoBlock { + pub: + seo_f1 string + seo_is_f1_capitalize bool + seo_params string +} + +fn main() { + db := sqlite.connect('test.db') or { panic(err) } + + sql db { + update SeoBlock set seo_f1 = seo_f1 where seo_f1 == "" + } or { panic(err) } +}