Hello hackers, since both `##sys#macro-environment` and `##sys#current-environment` are alists whose keys are unqualified symbol names it doesn't make sense to use `var` as lookup key since after the initial lookup of `var0` against the environment we possibly get back a fully-qualified symbol thus making the lookup fail. You can see by yourself by compiling the following snippet with C5:
``` (module foo () (import scheme data-structures) (define-syntax bar (syntax-rules ())) (set! bar 42) (set! alist-ref 42) ) ``` When compiled with the patch attached the compiler gives the following warnings (you need to pass -:d to enable the notices): Warning: (/tmp/foo.scm:5) - assigned global variable `foo#bar' is syntax Note: (/tmp/foo.scm:6) - assignment to imported value binding `chicken.data-structures#alist-ref' I don't know if the same treatment should be applied to the `keyword?` test below, if it can be folded inside the `cond` and whether it is a good idea to turn the notice into a warning but I'm running short on time :) I'm happy to adjust the patch according to your feedback here or on irc. Cheers, Lemonboy
From 65edffba15ae3b5c37acd316ef544d02f3019d2e Mon Sep 17 00:00:00 2001 From: LemonBoy <thatle...@gmail.com> Date: Tue, 9 May 2017 15:29:04 +0200 Subject: [PATCH] Use the non-qualified variable name in env lookups By the time the checks are executed the `var` has been probably converted into its fully-qualified name, causing the lookups to fail unconditionally. --- core.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core.scm b/core.scm index 8f68e3fa..fae9ceca 100644 --- a/core.scm +++ b/core.scm @@ -1108,14 +1108,16 @@ `(let ((,var ,val)) (##core#debug-event "C_DEBUG_GLOBAL_ASSIGN" ',var) ,var)))) - (cond ((##sys#macro? var) + ;; Here `var` may be a fully-qualified symbol, we have to use the "raw" variable name as + ;; key into the environments in the following checks. + (cond ((##sys#macro? var0) (warning (sprintf "~aassigned global variable `~S' is syntax" (if ln (sprintf "(~a) - " ln) "") var)) (when undefine-shadowed-macros (##sys#undefine-macro! var))) ((and ##sys#notices-enabled - (assq var (##sys#current-environment))) + (assq var0 (##sys#current-environment))) (##sys#notice (sprintf "~aassignment to imported value binding `~S'" (if ln (sprintf "(~a) - " ln) "") -- 2.12.2
_______________________________________________ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers