diff --git a/collects/tests/racket/read.rktl b/collects/tests/racket/read.rktl index 38f93b84d3..3ccbb96391 100644 --- a/collects/tests/racket/read.rktl +++ b/collects/tests/racket/read.rktl @@ -1103,6 +1103,13 @@ ;; Check error-message formatting: (err/rt-test (read (open-input-string "#l")) (lambda (exn) (regexp-match? #rx"`#l'" (exn-message exn)))) +;; Make sure read-language error here is this can comes from read-language +;; and not from an ill-formed srcloc construction: +(let () + (define p (open-input-string ";\n")) + (port-count-lines! p) + (err/rt-test (read-language p) + (lambda (exn) (regexp-match? #rx"read-language" (exn-message exn))))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/racket/src/read.c b/src/racket/src/read.c index 6f0535b408..fb99bc50eb 100644 --- a/src/racket/src/read.c +++ b/src/racket/src/read.c @@ -992,6 +992,13 @@ read_inner_inner(Scheme_Object *port, Scheme_Object *stxsrc, Scheme_Hash_Table * dispatch_ch = ch; if (get_info && (dispatch_ch != '#') && (dispatch_ch != ';')) { + /* If ch is EOF, then col or pos wasn't incremented by reading ch. + The col and pos might be used in an error message, which expects + to subtract one from each --- so counteract by adding one here. */ + if (ch == EOF) { + if (pos >= 0) pos++; + if (col >= 0) col++; + } return expected_lang("", ch, port, stxsrc, line, col, pos, get_info); }