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.
This commit is contained in:
Justin Ethier 2020-07-23 12:23:42 -04:00
parent 1670670968
commit e6d654b4a4

View file

@ -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)))