diff --git a/lib/read.c b/lib/read.c index 4a11257..dc384ca 100644 --- a/lib/read.c +++ b/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 diff --git a/t/fun-01.hcl b/t/fun-01.hcl index c9d936b..7bb3e99 100644 --- a/t/fun-01.hcl +++ b/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 | { diff --git a/t/run.sh b/t/run.sh index b8e8a96..bcc5e83 100644 --- a/t/run.sh +++ b/t/run.sh @@ -1,5 +1,6 @@ #!/bin/sh ## use a subshell to execute the actual program in case the ## program crashes or exits without an error message. +echo RUN "[$@]" ($@ 2>&1 || echo "ERROR: exited with $?") | grep -E '^ERROR:' && exit 1 exit 0