From a0c126423c0de8be4e5f997b1a82e51aef953bbf Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Fri, 5 Apr 2019 16:15:23 +0200 Subject: [PATCH] Reject import of module currently being defined (fixes #1506) --- NEWS | 6 ++++++ expand.scm | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 825acbfb..dba12ad9 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,12 @@ - When using (set-file-position!) on a port, its EOF status will now be reset. +- 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 - Type system diff --git a/expand.scm b/expand.scm index ec302d48..7517b052 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) -- 2.11.0