diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-10-15 16:41:14 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-10-15 18:50:22 +0200 |
| commit | 5ef1508942ee083ed22b844f5291e59320016b79 (patch) | |
| tree | d4133efbe23e696d8633339b74808b1ff6a1c86b | |
| parent | 48720afb322ab5ad1b6102276f4795a14803fa61 (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.scm | 3 | ||||
| -rw-r--r-- | tests/guix-build.sh | 27 |
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 | ||
| 199 | rm -f "$module_dir"/* | 199 | rm -f "$module_dir"/* |
| 200 | 200 | ||
| 201 | # Unbound variable: don't suggest modules that do not export the variable. | ||
| 202 | cat > "$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 | ||
| 206 | EOF | ||
| 207 | |||
| 208 | cat > "$module_dir/bb-public.scm" <<EOF | ||
| 209 | (define-module (bb-public) #:export (make-thing)) | ||
| 210 | (define make-thing identity) | ||
| 211 | EOF | ||
| 212 | |||
| 213 | cat > "$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) | ||
| 220 | EOF | ||
| 221 | ! guix build -f "$module_dir/cc-user.scm" -n 2> "$module_dir/err" | ||
| 222 | cat "$module_dir/err" | ||
| 223 | grep "make-thing.*unbound" "$module_dir/err" # actual error | ||
| 224 | grep "forget.*(bb-public)" "$module_dir/err" # hint | ||
| 225 | |||
| 226 | rm -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'. |
| 202 | cat > "$module_dir/foo.scm" <<EOF | 229 | cat > "$module_dir/foo.scm" <<EOF |
| 203 | (define-module (something foo) | 230 | (define-module (something foo) |
