From 4734fc1e40e2fac93fca59a9deb4206513ffe999 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 15 Jun 2020 11:51:32 +0900 Subject: [PATCH] friendlier report for error on module files with the wrong name (issue #624) --- lib/chibi/repl.scm | 52 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/chibi/repl.scm b/lib/chibi/repl.scm index 45c9084a..82877800 100644 --- a/lib/chibi/repl.scm +++ b/lib/chibi/repl.scm @@ -323,17 +323,49 @@ 0 (- (string-length mod-file) 4)) ".scm"))) - (display "Searched module path " out) - (display (current-module-path) out) - (display " for " out) - (write mod-file out) - (display ".\n" out) (cond - ((find-module-file scm-file) - => (lambda (file) - (display "But found non-module-definition file " out) - (write file out) - (display ".\nNote module files must end in \".sld\".\n" out))))) + ((find-module-file mod-file) + => (lambda (path) + (let ((defined-mod-name + (protect (exn (else #f)) + (let ((x (call-with-input-file path read))) + (and (pair? x) + (pair? (cdr x)) + (eq? 'define-library (car x)) + (cadr x)))))) + (cond + ((not defined-mod-name) + (display "File '" out) + (display path out) + (display "' does not appear to define module " out) + (display mod-name out) + (display ".\n" out)) + ((equal? defined-mod-name mod-name) + (display "File '" out) + (display path out) + (display "' failed to define module " out) + (display mod-name out) + (display ".\n" out)) + (else + (display "Expected file '" out) + (display path out) + (display "' to define module " out) + (display mod-name out) + (display " but found " out) + (display defined-mod-name out) + (display ".\n" out)))))) + (else + (display "Searched module path " out) + (display (current-module-path) out) + (display " for " out) + (write mod-file out) + (display ".\n" out) + (cond + ((find-module-file scm-file) + => (lambda (file) + (display "But found non-module-definition file " out) + (write file out) + (display ".\nNote module files must end in \".sld\".\n" out))))))) ))) (define undefined-value (if #f #f))