@@ -40,7 +40,8 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) ast.Type {
40
40
}
41
41
42
42
info := table_sym.info as ast.Struct
43
- mut fields := c.fetch_and_verify_orm_fields (info, node.table_expr.pos, table_sym.name)
43
+ mut fields := c.fetch_and_verify_orm_fields (info, node.table_expr.pos, table_sym.name,
44
+ node)
44
45
non_primitive_fields := c.get_orm_non_primitive_fields (fields)
45
46
mut sub_structs := map [int ]ast.SqlExpr{}
46
47
@@ -215,7 +216,8 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type {
215
216
}
216
217
217
218
info := table_sym.info as ast.Struct
218
- mut fields := c.fetch_and_verify_orm_fields (info, node.table_expr.pos, table_sym.name)
219
+ mut fields := c.fetch_and_verify_orm_fields (info, node.table_expr.pos, table_sym.name,
220
+ ast.SqlExpr{})
219
221
mut sub_structs := map [int ]ast.SqlStmtLine{}
220
222
non_primitive_fields := c.get_orm_non_primitive_fields (fields)
221
223
@@ -327,7 +329,7 @@ fn (mut c Checker) check_orm_struct_field_attributes(field ast.StructField) {
327
329
}
328
330
}
329
331
330
- fn (mut c Checker) fetch_and_verify_orm_fields (info ast.Struct, pos token.Pos, table_name string ) []ast.StructField {
332
+ fn (mut c Checker) fetch_and_verify_orm_fields (info ast.Struct, pos token.Pos, table_name string , sql_expr ast.SqlExpr ) []ast.StructField {
331
333
fields := info.fields.filter (fn [mut c] (field ast.StructField) bool {
332
334
is_primitive := field.typ.is_string () || field.typ.is_bool () || field.typ.is_number ()
333
335
is_struct := c.table.type_symbols[int (field.typ)].kind == .struct_
@@ -344,6 +346,18 @@ fn (mut c Checker) fetch_and_verify_orm_fields(info ast.Struct, pos token.Pos, t
344
346
return []ast.StructField{}
345
347
}
346
348
349
+ field_pos := c.orm_get_field_pos (sql_expr.where_expr)
350
+ for field in info.fields {
351
+ if c.table.sym (field.typ).kind == .array
352
+ && c.table.sym (c.table.sym (field.typ).array_info ().elem_type).is_primitive () {
353
+ c.add_error_detail ('' )
354
+ c.add_error_detail (' field name: `${field.name} `' )
355
+ c.add_error_detail (' data type: `${c.table.type_to_str(field.typ)} `' )
356
+ c.orm_error ('does not support array of primitive types' , field_pos)
357
+ return []ast.StructField{}
358
+ }
359
+ }
360
+
347
361
return fields
348
362
}
349
363
@@ -610,3 +624,24 @@ fn (_ &Checker) check_field_of_inserting_struct_is_uninitialized(node &ast.SqlSt
610
624
611
625
return false
612
626
}
627
+
628
+ fn (c &Checker) orm_get_field_pos (expr & ast.Expr) token.Pos {
629
+ mut pos := token.Pos{}
630
+ if expr is ast.InfixExpr {
631
+ if expr.left is ast.Ident {
632
+ pos = expr.left.pos
633
+ } else if expr.left is ast.InfixExpr || expr.left is ast.ParExpr
634
+ || expr.left is ast.PrefixExpr {
635
+ pos = c.orm_get_field_pos (expr.left)
636
+ } else {
637
+ pos = expr.left.pos ()
638
+ }
639
+ } else if expr is ast.ParExpr {
640
+ pos = c.orm_get_field_pos (expr.expr)
641
+ } else if expr is ast.PrefixExpr {
642
+ pos = c.orm_get_field_pos (expr.right)
643
+ } else {
644
+ pos = expr.pos ()
645
+ }
646
+ return pos
647
+ }
0 commit comments