checker: SqlStmt fixes

pull/5505/head
Alexander Medvednikov 2020-06-25 22:37:36 +02:00
parent 46379d92f4
commit aec7f2f6c4
1 changed files with 14 additions and 0 deletions

View File

@ -2722,12 +2722,26 @@ fn (mut c Checker) sql_stmt(mut node ast.SqlStmt) table.Type {
info := sym.info as table.Struct info := sym.info as table.Struct
fields := c.fetch_and_verify_orm_fields(info, node.pos, node.table_name) fields := c.fetch_and_verify_orm_fields(info, node.pos, node.table_name)
node.fields = fields node.fields = fields
// Register this type's fields as variables so they can be used in `where`
// expressions
scope := c.file.scope.innermost(node.pos.pos)
for field in fields {
// println('registering sql field var $field.name')
scope.register(field.name, ast.Var{
name: field.name
typ: field.typ
is_mut: true
is_used: true
is_changed: true
})
}
c.expr(node.db_expr) c.expr(node.db_expr)
if node.kind== .update { if node.kind== .update {
for expr in node.update_exprs { for expr in node.update_exprs {
c.expr(expr) c.expr(expr)
} }
} }
c.expr(node.where_expr)
return table.void_type return table.void_type
} }