RejectedSoftware Forums

Sign up

Lost Json value when calling runTask()

I tried to update my project to the latest version of dmd and vibe and received this error.

Tested with dmd 2.065 and 2.066 on Windows 7 x86 and x64.
Error occurs in vibe >=0.7.21-rc.3 (tested rc.2, rc.3, rc.4, master), driver win32 with code

void main()
{
    void func(Json c)
    {
        writeln(c);
    }

    Json config = Json(["id": Json(1001)]);
    runTask(&func, config);
    runEventLoop();
}

and that output:
undefined

When changing line

runTask(&func, config.id);

then output
Task terminated with uncaught exception: Got JSON of type int_, expected object.

Last error occurs ever if clear func()

void func(Json c){}

Re: Lost Json value when calling runTask()

Problem is in opDispatch method that allow such expressions as is(typeof(Json.init.hgfhk111) == Json) to be true. So my func is called inside runTask loop with argument config["move"] that is undefined. But vibe.core.core.needsMove(T) condition already have fixme comment...

Re: Lost Json value when calling runTask()

Am 04.11.2014 08:10, schrieb Alex Simonov:

Problem is in opDispatch method that allow such expressions as is(typeof(Json.init.hgfhk111) == Json) to be true. So my func is called inside runTask loop with argument config["move"] that is undefined. But vibe.core.core.needsMove(T) condition already have fixme comment...

Argh! I didn't think of opDispatch. The existing needsMove
implementation is just there because I failed to find a better solution.
Using !__traits(compiles, (){ T a, b; b = a; }()) unfortunately passes
for non-copyable types. I'll have to invest some more time to find an
alternative that makes the compiler happy.