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: Fix orm cast check #12018

Merged
merged 8 commits into from
Sep 29, 2021
4 changes: 4 additions & 0 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -7930,6 +7930,10 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) ast.Type {
sym := c.table.get_type_symbol(node.table_expr.typ)
c.ensure_type_exists(node.table_expr.typ, node.pos) or { return ast.void_type }
c.cur_orm_ts = *sym
if sym.info !is ast.Struct {
c.error('The table symbol `$sym.name` has to be a struct', node.table_expr.pos)
return ast.void_type
LouisSchmieder marked this conversation as resolved.
Show resolved Hide resolved
}
info := sym.info as ast.Struct
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, sym.name)
mut sub_structs := map[int]ast.SqlExpr{}
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/orm_not_a_struct.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vlib/v/checker/tests/orm_not_a_struct.vv:10:15: error: The table symbol `Person` has to be a struct
8 | db := sqlite.connect(':memory:')?
9 | _ := sql db {
10 | select from Person
| ~~~~~~
11 | }
12 | }
12 changes: 12 additions & 0 deletions vlib/v/checker/tests/orm_not_a_struct.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sqlite

enum Person {
test
}

fn main() {
db := sqlite.connect(':memory:')?
_ := sql db {
select from Person
}
}