Commit f176f05c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Allow automatic promotion from INT to REAL.

Fixes #2084
parent a630df00
varnishtest "REAL - INT types"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import std;
sub vcl_deliver {
set resp.http.add = 10.0 + std.integer(req.http.foo, 0);
set resp.http.sub = 10.0 - std.integer(req.http.foo, 0);
set resp.http.mul = 10.0 * std.integer(req.http.foo, 0);
set resp.http.div = 10.0 / std.integer(req.http.foo, 0);
}
} -start
client c1 {
txreq -hdr "foo: 3"
rxresp
expect resp.http.add == 13.000
expect resp.http.sub == 7.000
expect resp.http.mul == 30.000
expect resp.http.div == 3.333
} -run
......@@ -910,14 +910,13 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_NextToken(tl);
vcc_expr4(tl, &e2, f2);
ERRCHK(tl);
if (e2->fmt->multype == NULL) {
if (e2->fmt != REAL && e2->fmt != INT) {
VSB_printf(tl->sb,
"%s %.*s %s not possible.\n",
f2->name, PF(tk), e2->fmt->name);
vcc_ErrWhere(tl, tk);
return;
}
assert(e2->fmt == f2);
if (tk->tok == '*')
*e = vcc_expr_edit(f3, "(\v1*\v2)", *e, e2);
else
......@@ -1017,6 +1016,10 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt)
ADD_OK("-", INT, INT, INT);
ADD_OK("+", REAL, REAL, REAL);
ADD_OK("-", REAL, REAL, REAL);
ADD_OK("+", REAL, INT, REAL);
ADD_OK("-", REAL, INT, REAL);
ADD_OK("+", INT, REAL, REAL);
ADD_OK("-", INT, REAL, REAL);
#undef ADD_OK
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment