~ chicken-core (chicken-5) 2b4ded5946e5d4a7736d8229bfcc3bac2424448a


commit 2b4ded5946e5d4a7736d8229bfcc3bac2424448a
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Fri Apr 5 16:15:23 2019 +0200
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Sun Apr 7 15:40:51 2019 +1200

    Reject import of module currently being defined (fixes #1506)
    
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/NEWS b/NEWS
index ab9221fb..2d3e62fb 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,12 @@
   - Removed the unused, undocumented (and incorrect!) C functions
     C_delete_symbol_table and C_set_symbol_table.
 
+- Module system
+  - When you try to import the module you are currently defining into
+    itself, an error will be raised. This prevents an infinite loop in
+    the compiler when later trying to import that same module (fixes
+    #1506, thanks to Kristian Lein-Mathisen).
+
 
 5.0.1
 
diff --git a/expand.scm b/expand.scm
index ec302d48..c5ec3bcb 100644
--- a/expand.scm
+++ b/expand.scm
@@ -969,7 +969,11 @@
     (lambda (x r c)
       `(##core#begin
 	,@(map (lambda (x)
-		 (let-values (((name lib spec v s i) (##sys#decompose-import x r c 'import)))
+		 (let-values (((name lib spec v s i) (##sys#decompose-import x r c 'import))
+			      ((mod) (##sys#current-module)))
+		   (when (and mod (eq? name (##sys#module-name mod)))
+		     (##sys#syntax-error-hook
+		      'import "cannot import from module currently being defined" name))
 		   (if (not spec)
 		       (##sys#syntax-error-hook
 			'import "cannot import from undefined module" name)
Trap