From 8388c9416a2a99e667d80c546901a4d930ed1d69 Mon Sep 17 00:00:00 2001
From: Peter Bex <peter@more-magic.net>
Date: Sun, 11 Apr 2021 12:52:20 +0200
Subject: [PATCH] Resolve variable in set! using "lookup" when variable is not
global
This allows dropping the lookup in ##sys#current-environment
from ##sys#alias-global-hook because lookups when setting variables
now match lookups when dereferencing variables.
This currently only works inside the compiler; there is still a
problem in the interpreter causing the test to fail.
---
core.scm | 5 +++--
modules.scm | 2 +-
tests/module-tests.scm | 22 ++++++++++++++++++++++
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/core.scm b/core.scm
index 492a23a7..e3e173a4 100644
a
|
b
|
|
1174 | 1174 | ((assq var0 (##sys#current-environment)) |
1175 | 1175 | (warning |
1176 | 1176 | (sprintf "~aassignment to imported value binding `~S'" |
1177 | | (if ln (sprintf "(~a) - " ln) "") var0))))) |
1178 | | `(set! ,var ,(walk val e var0 (memq var e) h ln #f)))))) |
| 1177 | (if ln (sprintf "(~a) - " ln) "") var0))))) |
| 1178 | (let ((var (lookup var))) |
| 1179 | `(set! ,var ,(walk val e var0 (memq var e) h ln #f))))))) |
1179 | 1180 | |
1180 | 1181 | ((##core#debug-event) |
1181 | 1182 | `(##core#debug-event |
diff --git a/modules.scm b/modules.scm
index 29fb92e5..8393654f 100644
a
|
b
|
|
804 | 804 | (else sym))) |
805 | 805 | (cond ((keyword? sym) sym) |
806 | 806 | ((namespaced-symbol? sym) sym) |
807 | | ((assq sym (##sys#current-environment)) => |
| 807 | #;((assq sym (##sys#current-environment)) => |
808 | 808 | (lambda (a) |
809 | 809 | (let ((sym2 (cdr a))) |
810 | 810 | (dm "(ALIAS) in current environment " sym " -> " sym2) |
diff --git a/tests/module-tests.scm b/tests/module-tests.scm
index ec447e45..5054ee8a 100644
a
|
b
|
|
380 | 380 | (import (scheme) (chicken module)) |
381 | 381 | (eq? (current-module) 'm33))) |
382 | 382 | |
| 383 | ;; #1131 Undefined variables for macros from other modules should not |
| 384 | ;; be looked up in the current environment |
| 385 | (module undef (undefined) |
| 386 | (import scheme) |
| 387 | (define undefined 1)) |
| 388 | |
| 389 | (module expando (do-it) |
| 390 | (import scheme) |
| 391 | (define-syntax do-it |
| 392 | (syntax-rules () |
| 393 | ((_) |
| 394 | (let-syntax ((final |
| 395 | (syntax-rules () |
| 396 | ((_ ?x) ?x)))) |
| 397 | (final undefined)))))) |
| 398 | |
| 399 | (import undef expando) |
| 400 | ;; Should fail, not return 1, because the let-syntax expansion should |
| 401 | ;; rename introduced identifiers from its SE (but input should be |
| 402 | ;; looked up here) |
| 403 | (assert-error "Undefined variable should be undefined" (do-it)) |
| 404 | |
383 | 405 | (test-end "modules") |
384 | 406 | |
385 | 407 | (test-exit) |