waneck / mweb

2 stars 3 forks source link

Allow private typedef in HttpResponse type parameter #2

Open jonasmalacofilho opened 9 years ago

jonasmalacofilho commented 9 years ago
typedef Args = {
    msg : String
}
function doDefault(?args:Args):HttpResponse<Args>;
waneck commented 9 years ago

I'm not sure I understand what you mean. The following code works:

#if neko
import neko.Web;
#else
import php.Web;
#end
import mweb.tools.*;

typedef Args = { msg : String };

class Main extends mweb.Route<HttpResponse<Args>>
{
    public static function main()
    {
        var d = new mweb.Dispatcher(Web);
        var ret = d.dispatch(new Main());
        Sys.print(ret);
    }

    public function any():HttpResponse<Args>
    {
            return null;
    }
}

Also note that it's not doDefault, but anyDefault / getDefault / etc

jonasmalacofilho commented 9 years ago

A private typedef is actually required to trigger the error. I created the issue without building a minimum example first...

import mweb.tools.*;
import mweb.tools.HttpRequest;

#if alt
private typedef Args = { msg : String };
#else
typedef Args = { msg : String };
#end

class Request implements IHttpRequestData {
    public function new() {}

    public function getMethod()
        return 'GET';

    public function getUri()
        return '/';

    public function getParamsData()
        return [ "msg" => ["Some message"] ];
}

class BaseRoute extends mweb.Route<HttpResponse<Dynamic>> {}

class Route extends BaseRoute {
    public function getDefault(?args:Args):HttpResponse<Args>
    {
        return null;
    }
}

class Issue2 {
    public static function main()
    {
        var d = new mweb.Dispatcher(new Request());
        var ret = d.dispatch(new Route());
        Sys.print(ret);
    }
}

Finally, the doDefault was a typo from the old std.haxe.web.Dispatcher days; and any, get, etc also work (without "default"), am I correct?

waneck commented 9 years ago

Okay, it's indeed the private part which is breaking.

And yes - only any, get, etc also work. The default implies in "any otherwise unknown route"

waneck commented 9 years ago

I've reported the bug at https://github.com/HaxeFoundation/haxe/issues/3808 . Let's see if we'll need an ugly workaround or a prettier solution can be made to work. Anyway, right now it's best to stay away from private types :)