summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Meghan Denny2021-08-24 16:13:43 -0700
committerGravatar Meghan Denny2021-08-24 16:13:43 -0700
commit44029cd6e73fd0cdd418b48c0dcaaf7e1f5eca20 (patch)
treeca3f04517133ccf0779f6403a366dc5d2de59cda
parentfix type constraint checks for container and non-container types (diff)
downloadzig-sqlite-44029cd6e73fd0cdd418b48c0dcaaf7e1f5eca20.tar.gz
zig-sqlite-44029cd6e73fd0cdd418b48c0dcaaf7e1f5eca20.tar.xz
zig-sqlite-44029cd6e73fd0cdd418b48c0dcaaf7e1f5eca20.zip
dry up the updated constraint check
-rw-r--r--sqlite.zig25
1 files changed, 11 insertions, 14 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 67b67f5..abeea55 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -1053,20 +1053,11 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t
1053 .Typed => |typ| { 1053 .Typed => |typ| {
1054 const FieldTypeInfo = @typeInfo(struct_field.field_type); 1054 const FieldTypeInfo = @typeInfo(struct_field.field_type);
1055 switch (FieldTypeInfo) { 1055 switch (FieldTypeInfo) {
1056 .Struct, .Enum, .Union => { 1056 .Struct, .Enum, .Union => comptime assertMarkerType(
1057 if (@hasDecl(struct_field.field_type, "BaseType")) { 1057 if (@hasDecl(struct_field.field_type, "BaseType")) struct_field.field_type.BaseType else struct_field.field_type,
1058 if (struct_field.field_type.BaseType != typ) { 1058 typ,
1059 @compileError("value type " ++ @typeName(struct_field.field_type.BaseType) ++ " is not the bind marker type " ++ @typeName(typ)); 1059 ),
1060 } 1060 else => comptime assertMarkerType(struct_field.field_type, typ),
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 } 1061 }
1071 }, 1062 },
1072 .Untyped => {}, 1063 .Untyped => {},
@@ -1078,6 +1069,12 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t
1078 } 1069 }
1079 } 1070 }
1080 1071
1072 fn assertMarkerType(comptime Actual: type, comptime Expected: type) void {
1073 if (Actual != Expected) {
1074 @compileError("value type " ++ @typeName(Actual) ++ " is not the bind marker type " ++ @typeName(Expected));
1075 }
1076 }
1077
1081 fn bindField(self: *Self, comptime FieldType: type, comptime field_name: []const u8, i: c_int, field: FieldType) void { 1078 fn bindField(self: *Self, comptime FieldType: type, comptime field_name: []const u8, i: c_int, field: FieldType) void {
1082 const field_type_info = @typeInfo(FieldType); 1079 const field_type_info = @typeInfo(FieldType);
1083 const column = i + 1; 1080 const column = i + 1;