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

vibe-d-0.8.2 tree structure serialization still a problem #1941

Closed
tchaloupka opened this Issue Sep 29, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@tchaloupka
Copy link
Contributor

tchaloupka commented Sep 29, 2017

Partialy solved in #1855

But if we change the unittest from system to safe:

@safe unittest {
	import vibe.data.json;
	static struct Bar { Bar[] foos; int i; }
	auto b = deserializeJson!Bar(`{"i":1,"foos":[{"foos":[],"i":2}]}`);
	assert(b.i == 1);
	assert(b.foos.length == 1);
	assert(b.foos[0].i == 2);
}

We get:

data/vibe/data/serialization.d(799,30): Error: @safe function vibe.data.serialization.__unittestL796_160' cannot call @system function 'vibe.data.json.deserializeJson!(Bar, string).deserializeJson'

When we also use @optional on the array field we get:

data/vibe/data/serialization.d(752,30): Error: function vibe.data.json.JsonStringSerializer!(string, false).JsonStringSerializer.readDictionary!(Traits!(Bar, DefaultPolicy, optional)).readDictionary (scope void delegate(string) @safe entry_callback) is not callable using argument types (void) data/vibe/data/serialization.d(567,108): Error: template instance vibe.data.serialization.deserializeValueImpl!(JsonStringSerializer!(string, false), DefaultPolicy).deserializeValueDeduced!(Bar, optional) error instantiating
data/vibe/data/serialization.d(664,32):        instantiated from here: deserializeValue!(Bar, optional)
data/vibe/data/serialization.d(567,108):        instantiated from here: deserializeValueDeduced!(Bar[], optional)
data/vibe/data/serialization.d(767,48):        instantiated from here: deserializeValue!(Bar[], optional)
data/vibe/data/serialization.d(752,31):        ... (4 instantiations, -v to show) ...
data/vibe/data/json.d(1436,48):        instantiated from here: deserialize!(JsonStringSerializer!(string, false), Bar, string)
data/vibe/data/serialization.d(799,30):        instantiated from here: deserializeJson!(Bar, string)
data/vibe/data/serialization.d(752,30): Error: function vibe.data.json.JsonStringSerializer!(string, false).JsonStringSerializer.readDictionary!(Traits!(Bar, DefaultPolicy)).readDictionary (scope void delegate(string) @safe entry_callback) is not callable using argument types (void)
@timotheecour

This comment has been minimized.

Copy link

timotheecour commented Nov 27, 2017

also running into a similar issue (hard to reduce)

@s-ludwig

../../../.dub/packages/vibe-d-0.8.2-rc.1/vibe-d/data/vibe/data/serialization.d(752,30): Error: function vibe.data.bson.BsonSerializer.readDictionary!(Traits!(Foo, DefaultPolicy)).readDictionary (scope void delegate(string) @safe entry_callback) is not callable using argument types (void)
 ../../../.dub/packages/vibe-d-0.8.2-rc.1/vibe-d/data/vibe/data/serialization.d(565,114): Error: template instance vibe.data.serialization.deserializeValueImpl!(BsonSerializer, DefaultPolicy).deserializeValueDeduced!(Foo) error instantiating
 ../../../.dub/packages/vibe-d-0.8.2-rc.1/vibe-d/data/vibe/data/serialization.d(299,69):        instantiated from here: deserializeValue!(Foo)
 ../../../.dub/packages/vibe-d-0.8.2-rc.1/vibe-d/data/vibe/data/serialization.d(265,61):        instantiated from here: deserializeWithPolicy!(BsonSerializer, DefaultPolicy, Foo, Bson)
 ../../../.dub/packages/vibe-d-0.8.2-rc.1/vibe-d/data/vibe/data/bson.d(1168,41):        instantiated from here: deserialize!(BsonSerializer, Foo, Bson)
 bar.d:        ... (4 instantiations, -v to show) ...
 bar.d:        instantiated from here: map!(MongoCursor!(Bson, Bson, typeof(null)))
 baz.d:        instantiated from here: load!(Foo)
 ../../../.dub/packages/vibe-d-0.8.2-rc.1/vibe-d/data/vibe/data/serialization.d(565,114): Error: @safe function 'vibe.data.serialization.deserializeValueImpl!(BsonSerializer, DefaultPolicy).deserializeValue!(Foo).deserializeValue' cannot call @system function 'vibe.data.serialization.deserializeValueImpl!(BsonSerializer, DefaultPolicy).deserializeValueDeduced!(Foo).deserializeValueDeduced'

NOTE: problem doesn't happen with vibe-d-0.7.32

EDIT: possibly related to: #1991

s-ludwig added a commit that referenced this issue Dec 13, 2017

s-ludwig added a commit that referenced this issue Dec 14, 2017

@s-ludwig s-ludwig closed this in 5071ea1 Dec 22, 2017

@timotheecour

This comment has been minimized.

Copy link

timotheecour commented Feb 22, 2018

@s-ludwig could you perhaps re-open ? I'm still getting:

vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(576,114): Error: @safe function vibe.data.serialization.deserializeValueImpl!(BsonSerializer, PolicyCustom).deserializeValue!(foo1, optional).deserializeValue cannot call @system function vibe.data.serialization.deserializeValueImpl!(BsonSerializer, PolicyCustom).deserializeValueDeduced!(foo1, optional).deserializeValueDeduced
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(788,39): Error: template instance `vibe.data.serialization.deserializeValueImpl!(BsonSerializer, PolicyCustom).deserializeValue!(foo1, optional)` error instantiating
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(773,31):        instantiated from here: __lambda2!string
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(576,114):        instantiated from here: deserializeValueDeduced!(foo2, optional)
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(788,39):        instantiated from here: deserializeValue!(foo2, optional)
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(773,31):        ... (3 instantiations, -v to show) ...
fun1.d(1,1):        instantiated from here: deserializeWithPolicy!(BsonSerializer, PolicyCustom, foo3, Bson)
fun2.d(1,1):        instantiated from here: deserializeCustom!(foo3)

vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(773,30): Error: function vibe.data.bson.BsonSerializer.readDictionary!(Traits!(foo2, PolicyCustom, optional)).readDictionary(scope void delegate(string) @safe entry_callback) is not callable using argument types (void)
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(773,30):        cannot pass argument __lambda2 of type void to parameter scope void delegate(string) @safe entry_callback
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(773,30): Error: function vibe.data.bson.BsonSerializer.readDictionary!(Traits!(foo3, PolicyCustom)).readDictionary(scope void delegate(string) @safe entry_callback) is not callable using argument types (void)
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(773,30):        cannot pass argument __lambda2 of type void to parameter scope void delegate(string) @safe entry_callback
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(576,114): Error: @safe function vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValue!(foo4).deserializeValue cannot call @system function vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValueDeduced!(foo4).deserializeValueDeduced
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(299,69): Error: template instance `vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValue!(foo4)` error instantiating
vibe-d-0.8.3-alpha.4/vibe-d/data/vibe/data/serialization.d(265,61):        instantiated from here: deserializeWithPolicy!(JsonSerializer, DefaultPolicy, foo4, Json)

NOTE: it works if I apply this patch:



diff --git a/data/vibe/data/serialization.d b/data/vibe/data/serialization.d
index 0f1788ce..04ca3d63 100644
--- a/data/vibe/data/serialization.d
+++ b/data/vibe/data/serialization.d
@@ -578,14 +578,14 @@ private template deserializeValueImpl(Serializer, alias Policy) {
                T deserializeValue(T, ATTRIBUTES...)(ref Serializer ser) { return deserializeValueDeduced!(T, ATTRIBUTES)(ser); }
        }

-       T deserializeValueDeduced(T, ATTRIBUTES...)(ref Serializer ser) if(!isMutable!T)
+       T deserializeValueDeduced(T, ATTRIBUTES...)(ref Serializer ser) @trusted if(!isMutable!T)
        {
                import std.algorithm.mutation : move;
                auto ret = deserializeValue!(Unqual!T, ATTRIBUTES)(ser);
                return () @trusted { return cast(T)ret.move; } ();
        }

-       T deserializeValueDeduced(T, ATTRIBUTES...)(ref Serializer ser) if(isMutable!T)
+       T deserializeValueDeduced(T, ATTRIBUTES...)(ref Serializer ser) @trusted if(isMutable!T)
        {
                import std.typecons : BitFlags, Nullable, Typedef, TypedefType, Tuple;

is it desired?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment