added a double lambda test case
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
49ad657544
commit
081c6d1874
11
lib/read.c
11
lib/read.c
@ -1335,13 +1335,12 @@ static int feed_process_token (hcl_t* hcl)
|
||||
case HCL_TOK_LPAREN: /* ( */
|
||||
#if defined(HCL_LANG_AUTO_FORGE_XLIST_ALWAYS)
|
||||
/* with this feature on, you must not enclose an expression with ()
|
||||
* at the top-level or a the block level. If you do, it is interpreted as
|
||||
* double exuection, meaning the return value of the expression is
|
||||
* called again.
|
||||
*
|
||||
* (+ 10 20) as a leading expression is like ((+ 10 20)).
|
||||
* at the beginning of the top-level or at the beginning of a the block level.
|
||||
* If you do enclose an expression with an outer () there, it is interpreted as
|
||||
* double calls, meaning the return value of the expression is called again.
|
||||
* for example, '(+ 10 20)' as a leading expression is like '((+ 10 20))'.
|
||||
* -------------------------------------------------------------
|
||||
* However, it can be a bit confusing:
|
||||
* It is useful but a bit confusing:
|
||||
* defun x(a) { return (fun(b) { return (+ a b) }) }
|
||||
* printf "%d\n" ((x 10) 20) ## excplicit outer () is required here
|
||||
* (x 10) 30 ## explicit outer () must not be used here
|
||||
|
21
t/fun-01.hcl
21
t/fun-01.hcl
@ -18,7 +18,16 @@ defun mkfun(t) {
|
||||
return (fun(c) {
|
||||
return (+ t c);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
defun mkfund(t) {
|
||||
return {fun(c) {
|
||||
return (fun(d) {
|
||||
##return (d + c t) ## this causes assertion failure.
|
||||
return (d + c t)
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
f := (mkfun 20);
|
||||
set k (f 50);
|
||||
@ -38,7 +47,9 @@ if (k = 50) {
|
||||
};
|
||||
|
||||
k := {
|
||||
(mkfun 20) 30
|
||||
## the return value of this expression is ignored
|
||||
(mkfun 20) 30 ## having comment here cause an issue...
|
||||
## the return value of this expression is the return value of the block expression
|
||||
(mkfun 20) 40
|
||||
}
|
||||
if (k = 60) {
|
||||
@ -47,6 +58,12 @@ if (k = 60) {
|
||||
printf "ERROR - %d\n" k
|
||||
};
|
||||
|
||||
k := (((mkfund 10) 40) 30)
|
||||
if (k = 80) {
|
||||
printf "OK - %d\n" k
|
||||
} else {
|
||||
printf "ERROR - %d\n" k
|
||||
};
|
||||
## --------------------------------------
|
||||
|
||||
defclass A | a b c | {
|
||||
|
Loading…
Reference in New Issue
Block a user