~ chicken-core (chicken-5) fe4e2db7b36c46028f9dadcda19010d1f684c406
commit fe4e2db7b36c46028f9dadcda19010d1f684c406 Author: felix <felix@call-with-current-continuation.org> AuthorDate: Fri Nov 10 11:21:51 2023 +0100 Commit: Peter Bex <peter@more-magic.net> CommitDate: Fri Nov 10 14:47:36 2023 +0100 Resolve macro-aliases for static evaluation environments (#1295) When evaluating forms in a "static" environment, identifiers are not resolved using our old friend ##sys#alias-global-hook, but identifiers introduced by macros must still be replaced by their "##sys#macro-alias", which is correctly returned when looking up the identifier in the environment, but not used. Signed-off-by: Peter Bex <peter@more-magic.net> diff --git a/NEWS b/NEWS index 55b4cad1..32650079 100644 --- a/NEWS +++ b/NEWS @@ -55,6 +55,10 @@ (short: -l) to specify local directories where to get egg sources from. +- Syntax expander + - When passing a module as an environment to eval, correctly resolve + identifiers in macro expansions (#1295 reported by Caolan McMahon). + - Compiler - When emitting types files, the output list is now sorted, to ensure deterministic build output (fixes #1783, reported by "ss2"). diff --git a/eval.scm b/eval.scm index 4562a506..68fba6ff 100644 --- a/eval.scm +++ b/eval.scm @@ -145,8 +145,9 @@ (let ((var (cond ((not (symbol? j)) x) ; syntax? ((assq x (##sys#current-environment)) j) ((not static) - (##sys#alias-global-hook j #f cntr)) - (else #f)))) + (##sys#alias-global-hook j #f cntr)) + ((not (eq? x j)) j) ; has macro-alias + (else #f)))) (when (and ##sys#unbound-in-eval (or (not var) (not (##sys#symbol-has-toplevel-binding? var)))) diff --git a/tests/environment-tests.scm b/tests/environment-tests.scm index b4143a52..c9d22d46 100644 --- a/tests/environment-tests.scm +++ b/tests/environment-tests.scm @@ -1,6 +1,6 @@ ;;;; environment-tests.scm -(import (chicken load)) +(import (chicken load) (chicken eval)) (load-relative "test.scm") @@ -53,6 +53,16 @@ (test-equal (eval '(format "~a" 1) format-env) "1") (test-error (eval 'baz format-env)) +;; #1295 +(module example * + (import scheme) + (define (add a b) (+ a b)) + (define-syntax double + (syntax-rules () + ((_ x) (add x x))))) + +(test-equal (eval '(double 10) (module-environment 'example)) 20) + (test-end) (test-exit)Trap