Skip to content

Commit

Permalink
Fix :web for non-class HTTPServerRequest.
Browse files Browse the repository at this point in the history
Makes the code forward-compatible with a switch from class to struct for HTTPServerRequest.
  • Loading branch information
s-ludwig committed Feb 17, 2024
1 parent 62d43f5 commit 8eebfce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions web/vibe/web/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -1256,11 +1256,11 @@ package void setVoid(T, U)(ref T dst, U value)
}

unittest {
static assert(!__traits(compiles, { bool[] barr; ParamError err;readFormParamRec(null, barr, "f", true, NestedNameStyle.d, err); }));
static assert(__traits(compiles, { bool[2] barr; ParamError err;readFormParamRec(null, barr, "f", true, NestedNameStyle.d, err); }));
static assert(!__traits(compiles, { bool[] barr; ParamError err;readFormParamRec(HTTPServerRequest.init, barr, "f", true, NestedNameStyle.d, err); }));
static assert(__traits(compiles, { bool[2] barr; ParamError err;readFormParamRec(HTTPServerRequest.init, barr, "f", true, NestedNameStyle.d, err); }));

enum Test: string { a = "AAA", b="BBB" }
static assert(__traits(compiles, { Test barr; ParamError err;readFormParamRec(null, barr, "f", true, NestedNameStyle.d, err); }));
static assert(__traits(compiles, { Test barr; ParamError err;readFormParamRec(HTTPServerRequest.init, barr, "f", true, NestedNameStyle.d, err); }));
}

private string getArrayFieldName(T)(NestedNameStyle style, string prefix, T index)
Expand Down
4 changes: 2 additions & 2 deletions web/vibe/web/i18n.d
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ package string determineLanguage(alias METHOD)(scope HTTPServerRequest req)

unittest { // make sure that the custom determineLanguage is called
static struct CTX {
static string determineLanguage(Object a) { return "test"; }
static string determineLanguage(HTTPServerRequest a) { return "test"; }
}
@translationContext!CTX
static class Test {
Expand All @@ -350,7 +350,7 @@ unittest { // make sure that the custom determineLanguage is called
}
}
auto test = new Test;
assert(determineLanguage!(test.test)(null) == "test");
assert(determineLanguage!(test.test)(HTTPServerRequest.init) == "test");
}

unittest { // issue #1955
Expand Down
2 changes: 1 addition & 1 deletion web/vibe/web/web.d
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ private struct RequestContext {

private RequestContext getRequestContext()
@trusted nothrow {
assert(s_requestContext.req !is null, "Request context used outside of a web interface request!");
assert(s_requestContext.req !is HTTPServerRequest.init, "Request context used outside of a web interface request!");
return s_requestContext;
}

Expand Down

0 comments on commit 8eebfce

Please sign in to comment.