Prioritize fatal reader diagnostics
ober
71bce8529e4b462ef9d80aabb499557d093c29a6
--- a/src/jcode/core/verified-run.ss +++ b/src/jcode/core/verified-run.ss @@ -935,14 +935,18 @@ #f (let* ((diag-start (or (find-diagnostic-start detail - '("Exception: incorrect argument count in call" - "incorrect argument count in call")) - 0)) - (line-no (find-line-number-after-from detail " at line " diag-start))) - (and line-no - (let ((path (verification-source-path cwd detail line-no diag-start))) - (and path - (let ((p (abs-path cwd path))) + '("Exception: incorrect argument count in call" + "incorrect argument count in call")) + 0)) + (line-no (find-line-number-after-from detail " at line " diag-start))) + (and (or (not (string-contains detail "Exception")) + (string-prefix? "Exception" (substring detail diag-start + (min (string-length detail) + (+ diag-start 9))))) + line-no + (let ((path (verification-source-path cwd detail line-no diag-start))) + (and path + (let ((p (abs-path cwd path))) (and (file-exists? p) (let* ((lines (string-split (read-file-string p) #\newline)) (line (line-at lines line-no)) @@ -957,9 +961,23 @@ "(random range)")) (and (string-contains line "(getenv") (getenv-two-arg-candidate line)))))) - (make-required-range-repair - path line-no line-no line-no - 'call-arity candidate)))))))))) + (make-required-range-repair + path line-no line-no line-no + 'call-arity candidate)))))))))) + +(def (reader-syntax-repair detail cwd) + (and (string-contains detail "invalid sharp-sign prefix") + (let* ((diag-start (or (find-diagnostic-start + detail + '("invalid sharp-sign prefix")) + 0)) + (line-no (find-line-number-after-from detail " at line " diag-start))) + (and line-no + (let ((path (verification-source-path cwd detail line-no diag-start))) + (and path + (file-exists? (abs-path cwd path)) + (make-required-range-repair + path line-no line-no line-no 'reader-syntax))))))) (def (unbound-variable-name detail) (let ((marker "variable ") @@ -1539,6 +1557,7 @@ (or (invalid-context-repair detail cwd) (no-expressions-repair detail cwd) (invalid-syntax-repair detail cwd) + (reader-syntax-repair detail cwd) (call-arity-repair detail cwd) (unbound-symbol-repair detail cwd) (runtime-call-arity-repair detail cwd) @@ -1741,8 +1760,20 @@ label) (if (repair-ref repair 'candidate) " Jerboa random accepts one upper-bound argument; remove the explicit random-state argument." - "") - (best-repair-candidate-text cwd repair label)))))) + "") + (best-repair-candidate-text cwd repair label)))))) + +(def (reader-syntax-diagnosis detail cwd) + (let ((repair (reader-syntax-repair detail cwd))) + (and repair + (string-append + (format + "\n\nReader syntax diagnosis: verifier reported a source reader error in ~a at line ~a. Repair that exact line with line_edit or replace_range, then call verify." + (repair-ref repair 'path) + (repair-ref repair 'line)) + (if (string-contains detail "invalid sharp-sign prefix") + " A stray `#` before a string or datum is invalid reader syntax; remove it or replace the form with valid quoted data." + ""))))) (def (unbound-symbol-diagnosis detail cwd) (let ((repair (unbound-symbol-repair detail cwd))) @@ -1808,6 +1839,7 @@ (let* ((diagnosis (or (invalid-context-diagnosis detail cwd) (empty-body-diagnosis detail cwd) (invalid-syntax-diagnosis detail cwd) + (reader-syntax-diagnosis detail cwd) (call-arity-diagnosis detail cwd) (unsupported-iteration-diagnosis detail cwd) (unbound-symbol-diagnosis detail cwd) --- a/test/run.ss +++ b/test/run.ss @@ -7008,12 +7008,39 @@ (and (str-contains? s "Syntax diagnosis") (str-contains? s "start=5") (str-contains? s "end=9") - (str-contains? s "(define (bad row)") - (not (str-contains? s "start=2")))))) - (safe-delete-test-file! target-path)) + (str-contains? s "(define (bad row)") + (not (str-contains? s "start=2")))))) + (safe-delete-test-file! target-path)) - (let* ([vr-dir "/tmp"] - [target "jcode-invalid-syntax-generated-range.ss"] + (let* ([vr-dir "/tmp"] + [target "jcode-reader-fatal-after-warning.ss"] + [target-path (string-append vr-dir "/" target)] + [bad-source "(import (jerboa prelude))\n(def (rng) (random-integer rng N-TYPES))\n(def (handle code)\n (case code\n [(# \"Left\") #t]\n [else #f]))\n"]) + (safe-delete-test-file! target-path) + (write-test-output-file target-path + (lambda (o) (display bad-source o)) + 'replace) + (let* ([cmd (string-append + "printf '%s\\n' 'Warning in compile: possible incorrect argument count in call (random-integer rng N-TYPES) at line 2, char 12 of " + target + "' >&2; printf '%s\\n' 'Exception in read: invalid sharp-sign prefix # at line 5, char 7 of " + target + "' >&2; exit 255")] + [result (run-verify-command cmd vr-dir)] + [detail (cdr result)]) + (check! "verified-run: reader fatal after warning fake verify fails" + (car result) #f) + (check-pred! "verified-run: reader fatal after warning uses fatal line" + detail + (lambda (s) + (and (str-contains? s "Reader syntax diagnosis") + (str-contains? s "line 5") + (str-contains? s "invalid sharp-sign prefix") + (not (str-contains? s "Call arity diagnosis")))))) + (safe-delete-test-file! target-path)) + + (let* ([vr-dir "/tmp"] + [target "jcode-invalid-syntax-generated-range.ss"] [target-path (string-append vr-dir "/" target)] [bad-source "(import (jerboa prelude))\n(define (bad row)\n (do ((x 0 (+ x 1))\n ((= x 3))\n (displayln x)))\n\n(define (later)\n (displayln \"later\")))\n"] [wrong-span "(define (bad row)\n (do ((x 0 (+ x 1))\n ((= x 3)))\n (displayln x)))"]