summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Meghan Denny2021-08-24 16:04:32 -0700
committerGravatar Meghan Denny2021-08-24 16:04:32 -0700
commit2fc1ca7ec801ea97140998582e8e05431da24cbb (patch)
tree60a2f0e39e15212f84c145636e87442224dafde5 /sqlite.zig
parentenum tests now pass without orelse in read (diff)
downloadzig-sqlite-2fc1ca7ec801ea97140998582e8e05431da24cbb.tar.gz
zig-sqlite-2fc1ca7ec801ea97140998582e8e05431da24cbb.tar.xz
zig-sqlite-2fc1ca7ec801ea97140998582e8e05431da24cbb.zip
fix type constraint checks for container and non-container types
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig20
1 files changed, 18 insertions, 2 deletions
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
1050 inline for (StructTypeInfo.fields) |struct_field, _i| { 1050 inline for (StructTypeInfo.fields) |struct_field, _i| {
1051 const bind_marker = query.bind_markers[_i]; 1051 const bind_marker = query.bind_markers[_i];
1052 switch (bind_marker) { 1052 switch (bind_marker) {
1053 .Typed => |typ| if (struct_field.field_type != typ and struct_field.field_type.BaseType != typ) { 1053 .Typed => |typ| {
1054 @compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ)); 1054 const FieldTypeInfo = @typeInfo(struct_field.field_type);
1055 switch (FieldTypeInfo) {
1056 .Struct, .Enum, .Union => {
1057 if (@hasDecl(struct_field.field_type, "BaseType")) {
1058 if (struct_field.field_type.BaseType != typ) {
1059 @compileError("value type " ++ @typeName(struct_field.field_type.BaseType) ++ " is not the bind marker type " ++ @typeName(typ));
1060 }
1061 } else if (struct_field.field_type != typ) {
1062 @compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ));
1063 }
1064 },
1065 else => {
1066 if (struct_field.field_type != typ) {
1067 @compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ));
1068 }
1069 },
1070 }
1055 }, 1071 },
1056 .Untyped => {}, 1072 .Untyped => {},
1057 } 1073 }