From e6d654b4a4ff9d02cd595f63139bb70b3d1b7c20 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 23 Jul 2020 12:23:42 -0400 Subject: [PATCH] Prevent line number info from being added twice Since we now call error/loc in the macro expander, it is possible we are double-calling it if a macro is also calling it directly to report a syntax error. We need to detect that case and only add location information (line, column, filename) if it has not already been added to the error message. --- scheme/base.sld | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scheme/base.sld b/scheme/base.sld index 1bdedd90..b1a682ab 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -236,18 +236,24 @@ (begin (define *source-loc-lis* '()) (define (error/loc reason expr . args) + ;; Does reason already include line/file location info? + (define (reason/line-loc? reason) + (and (string? reason) + (equal? (substring reason 0 9) + "(at line "))) (let* ((found (assoc expr *source-loc-lis*)) (loc-vec (if found (cdr found) ;; Get value #f)) - (msg (if loc-vec + (msg (if (and loc-vec ;; Have line info + (not (reason/line-loc? reason))) ;; Not there yet (string-append - "(" - (vector-ref loc-vec 0) - " line " + "(at line " (number->string (vector-ref loc-vec 1)) ", column " (number->string (vector-ref loc-vec 2)) + " of " + (vector-ref loc-vec 0) ") " reason) reason)))