Skip to content

Commit fb0fe11

Browse files
author
WebFreak001
committed
Fixed null types
1 parent 8afaf50 commit fb0fe11

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

source/mongoschema/package.d

+11-4
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,12 @@ private T bsonToMember(T)(auto ref T member, Bson value)
209209
/// Generates a Bson document from a struct/class object
210210
Bson toSchemaBson(T)(T obj)
211211
{
212-
static if (__traits(compiles, cast(T) null))
212+
static if (__traits(compiles, cast(T) null) && __traits(compiles, {
213+
T foo = null;
214+
}))
213215
{
214-
return Bson(null);
216+
if (obj is null)
217+
return Bson(null);
215218
}
216219

217220
Bson data = Bson.emptyObject;
@@ -294,7 +297,9 @@ Bson toSchemaBson(T)(T obj)
294297
/// Generates a struct/class object from a Bson node
295298
T fromSchemaBson(T)(Bson bson)
296299
{
297-
static if (__traits(compiles, cast(T) null))
300+
static if (__traits(compiles, cast(T) null) && __traits(compiles, {
301+
T foo = null;
302+
}))
298303
{
299304
if (bson.isNull)
300305
return null;
@@ -358,7 +363,9 @@ T fromSchemaBson(T)(Bson bson)
358363
}
359364
else
360365
{
361-
mixin("obj." ~ memberName ~ " = bsonToMember(obj." ~ memberName ~ ", bson[name]);");
366+
mixin(
367+
"obj." ~ memberName ~ " = bsonToMember(obj."
368+
~ memberName ~ ", bson[name]);");
362369
}
363370
}
364371
}

0 commit comments

Comments
 (0)