Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify deserialize on Variant!(void, T) #28

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/mir/deser/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,8 @@ template deserializeValue(string[] symbolTable, TableKind tableKind)
return retNull;
}
}
static if ((contains!(typeof(null)) || contains!IonNull) && T.AllowedTypes.length == 2)
static if (T.AllowedTypes.length == 2
&& (contains!(typeof(null)) || contains!IonNull || is(T.AllowedTypes[0] == void)))
{
T.AllowedTypes[1] payload;
if (auto exception = deserializeValue(data, payload, table, tableIndex))
Expand Down
6 changes: 4 additions & 2 deletions source/mir/ion/examples.d
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ version(mir_ion_test) unittest
version(mir_ion_test) unittest
{
import mir.serde: serdeEnumProxy;
import mir.algebraic: Nullable, nullable;
import mir.algebraic: Nullable, Variant, nullable;

@serdeEnumProxy!string
enum StrE : string
Expand All @@ -1420,13 +1420,15 @@ version(mir_ion_test) unittest
static struct S
{
Nullable!(StrE[]) a;
Variant!(void, StrE) b;
}

import mir.ser.json : serializeJson;
import mir.deser.json : deserializeJson;

auto s = S([StrE.one, StrE.two, cast(StrE)"drei"].nullable);
auto str = `{"a":["eins","zwei","drei"]}`;
s.b = StrE.two;
auto str = `{"a":["eins","zwei","drei"],"b":"zwei"}`;

assert(str.deserializeJson!S == s);
assert(s.serializeJson == str, str);
Expand Down