From 2fc1ca7ec801ea97140998582e8e05431da24cbb Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 24 Aug 2021 16:04:32 -0700 Subject: fix type constraint checks for container and non-container types --- sqlite.zig | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index a72a143..67b67f5 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -1050,8 +1050,24 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t inline for (StructTypeInfo.fields) |struct_field, _i| { const bind_marker = query.bind_markers[_i]; switch (bind_marker) { - .Typed => |typ| if (struct_field.field_type != typ and struct_field.field_type.BaseType != typ) { - @compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ)); + .Typed => |typ| { + const FieldTypeInfo = @typeInfo(struct_field.field_type); + switch (FieldTypeInfo) { + .Struct, .Enum, .Union => { + if (@hasDecl(struct_field.field_type, "BaseType")) { + if (struct_field.field_type.BaseType != typ) { + @compileError("value type " ++ @typeName(struct_field.field_type.BaseType) ++ " is not the bind marker type " ++ @typeName(typ)); + } + } else if (struct_field.field_type != typ) { + @compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ)); + } + }, + else => { + if (struct_field.field_type != typ) { + @compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ)); + } + }, + } }, .Untyped => {}, } -- cgit v1.2.3