diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index 1d0d7bcc5..ab91aba96 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -449,8 +449,11 @@ static te_expr *base(state *s) { case TOK_OPEN: next_token(s); ret = expr(s); - if (s->type == TOK_CLOSE) { + if (s->type == TOK_CLOSE) next_token(s); + else if (s->type != TOK_ERROR && s->type != TOK_END && s->error == TE_ERROR_NONE) { + s->type = TOK_ERROR; + s->error = TE_ERROR_TOO_MANY_ARGS; } else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) { s->type = TOK_ERROR; s->error = TE_ERROR_MISSING_CLOSING_PAREN; diff --git a/tests/checks/math.fish b/tests/checks/math.fish index 9575c83c7..b8f519df1 100644 --- a/tests/checks/math.fish +++ b/tests/checks/math.fish @@ -129,6 +129,18 @@ not math '2 + 2 4' # CHECKERR: math: Error: Too many arguments # CHECKERR: '2 + 2 4' # CHECKERR: ^ +not math '(1 2)' +# CHECKERR: math: Error: Too many arguments +# CHECKERR: '(1 2)' +# CHECKERR: ^ +not math '(1 pi)' +# CHECKERR: math: Error: Too many arguments +# CHECKERR: '(1 pi)' +# CHECKERR: ^ +not math '(1 pow 1,2)' +# CHECKERR: math: Error: Too many arguments +# CHECKERR: '(1 pow 1,2)' +# CHECKERR: ^ not math # CHECKERR: math: expected >= 1 arguments; got 0 not math -s 12 @@ -182,6 +194,11 @@ math 'log(16' # CHECKERR: 'log(16' # CHECKERR: ^ +math '(2' +# CHECKERR: math: Error: Missing closing parenthesis +# CHECKERR: '(2' +# CHECKERR: ^ + math --base=16 255 / 15 # CHECK: 0x11 math -bhex 16 x 2