From fb292fec3315be8b8469843d06053ccacfb540b0 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 3 Nov 2026 00:14:53 +0100 Subject: fn.c: Improve diagnostics for unexpected words --- src/prc1/fn.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/prc1/fn.c b/src/prc1/fn.c index 3a9809e..fa18f81 100644 --- a/src/prc1/fn.c +++ b/src/prc1/fn.c @@ -27,20 +27,22 @@ static const struct seq fnseq[] = int fn_end(const struct lex *l, struct prv *p) { const struct fn *fn = fn_cur(p); + const struct tk *tk = fn->tk; if (!fn->pr) { - const struct tk *tk = fn->tk; const char *s = p->proto ? "prototype" : "function"; - errloc(p->stk - 1, "%s \"%s\" has no procedure", s, tk->s); + if (lex_eof(l, p->tk)) + errloc(p->tk - 1, "%s \"%s\" has no procedure", s, tk->s); + else + errloc(p->tk, "unexpected \"%s\"", p->tk->s); + return -1; } else if (fn->nblocks) { - const struct tk *tk = lex_eof(l, p->stk) ? p->tk - 1 : p->stk; - - errloc(tk, "missing \"end\" in function \"%s\"", fn->tk->s); + errloc(tk, "missing \"end\" in function \"%s\"", tk->s); return -1; } -- cgit v1.2.3