summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-10-15 16:41:14 +0200
committerLudovic Courtès <ludo@gnu.org>2020-10-15 18:50:22 +0200
commit5ef1508942ee083ed22b844f5291e59320016b79 (patch)
treed4133efbe23e696d8633339b74808b1ff6a1c86b
parent48720afb322ab5ad1b6102276f4795a14803fa61 (diff)
ui: Only suggest modules that export the unbound variable identifier.
Fixes <https://bugs.gnu.org/43498>. Reported by Tobias Geerinckx-Rice <me@tobias.gr>. * guix/ui.scm (known-variable-definition): Check for variables in the public interface of HEAD, not in HEAD itself. * tests/guix-build.sh: Add test.
-rw-r--r--guix/ui.scm3
-rw-r--r--tests/guix-build.sh27
2 files changed, 29 insertions, 1 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index 8213e8ebabc..8d7bc238bc6 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -297,7 +297,8 @@ VARIABLE and return it, or #f if none was found."
297 (hash-map->list (lambda (name module) 297 (hash-map->list (lambda (name module)
298 module) 298 module)
299 (module-submodules head))))) 299 (module-submodules head)))))
300 (match (module-local-variable head variable) 300 (match (and=> (module-public-interface head)
301 (cut module-local-variable <> variable))
301 (#f (loop next suggestions visited)) 302 (#f (loop next suggestions visited))
302 (_ 303 (_
303 (match (module-name head) 304 (match (module-name head)
diff --git a/tests/guix-build.sh b/tests/guix-build.sh
index 6dbb53206e6..4a58ea1476c 100644
--- a/tests/guix-build.sh
+++ b/tests/guix-build.sh
@@ -198,6 +198,33 @@ grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
198 198
199rm -f "$module_dir"/* 199rm -f "$module_dir"/*
200 200
201# Unbound variable: don't suggest modules that do not export the variable.
202cat > "$module_dir/aa-private.scm" <<EOF
203(define-module (aa-private))
204(define make-thing #f)
205(set! make-thing make-thing) ;don't inline
206EOF
207
208cat > "$module_dir/bb-public.scm" <<EOF
209(define-module (bb-public) #:export (make-thing))
210(define make-thing identity)
211EOF
212
213cat > "$module_dir/cc-user.scm" <<EOF
214;; Make those module available in the global name space.
215(load-from-path "aa-private.scm")
216(load-from-path "bb-public.scm")
217
218(define-module (cc-user))
219(make-thing 42)
220EOF
221! guix build -f "$module_dir/cc-user.scm" -n 2> "$module_dir/err"
222cat "$module_dir/err"
223grep "make-thing.*unbound" "$module_dir/err" # actual error
224grep "forget.*(bb-public)" "$module_dir/err" # hint
225
226rm -f "$module_dir"/*
227
201# Wrong 'define-module' clause reported by 'warn-about-load-error'. 228# Wrong 'define-module' clause reported by 'warn-about-load-error'.
202cat > "$module_dir/foo.scm" <<EOF 229cat > "$module_dir/foo.scm" <<EOF
203(define-module (something foo) 230(define-module (something foo)