Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker.orm: check if update expr is invalid ident #21174

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vlib/orm/orm_null_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}!
}

Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/orm.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/orm_update_right_type_ident_err.out
Original file line number Diff line number Diff line change
@@ -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 | }
18 changes: 18 additions & 0 deletions vlib/v/checker/tests/orm_update_right_type_ident_err.vv
Original file line number Diff line number Diff line change
@@ -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) }
}
Loading