From 9429d011b690372254bfc35ac6095c8a2dcd8c61 Mon Sep 17 00:00:00 2001 From: felix Date: Fri, 10 Nov 2023 11:21:51 +0100 Subject: [PATCH] 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. --- eval.scm | 5 +++-- tests/environment-tests.scm | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) 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) -- 2.40.0