Improve special-casing of `_' in `-Wformat'.
authorLudovic Courtès <ludo@gnu.org>
Sat, 12 May 2012 13:31:28 +0000 (15:31 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sat, 12 May 2012 13:31:28 +0000 (15:31 +0200)
* module/language/tree-il/analyze.scm (proc-ref?): Check for
  SPECIAL-NAME in the <module-ref> and <lexical-ref> cases too.

* test-suite/tests/tree-il.test ("warnings")["format"]("non-literal
  format string using gettext as module-ref _", "non-literal format
  string using gettext as lexical _"): New tests.

module/language/tree-il/analyze.scm
test-suite/tests/tree-il.test

index 1fd8d58..76923fc 100644 (file)
@@ -1359,9 +1359,13 @@ resort, return #t when EXP refers to the global variable SPECIAL-NAME."
     (($ <module-ref> _ module name public?)
      (let* ((mod (if public?
                      (false-if-exception (resolve-interface module))
-                     (resolve-module module #:ensure? #f)))
+                     (resolve-module module #:ensure #f)))
             (var (and mod (module-variable mod name))))
-       (and var (variable-bound? var) (eq? (variable-ref var) proc))))
+       (if var
+           (and (variable-bound? var) (eq? (variable-ref var) proc))
+           (eq? name special-name))))
+    (($ <lexical-ref> _ (? (cut eq? <> special-name)))
+     #t)
     (_ #f)))
 
 (define gettext? (cut proc-ref? <> gettext '_ <>))
index 2b07e62..28c0b26 100644 (file)
                           #:opts %opts-w-format
                           #:to 'assembly)))))
 
+     (pass-if "non-literal format string using gettext as module-ref _"
+       (null? (call-with-warnings
+               (lambda ()
+                 (compile '(format #t ((@@ (foo) _) "~A ~A!") "hello" "world")
+                          #:opts %opts-w-format
+                          #:to 'assembly)))))
+
+     (pass-if "non-literal format string using gettext as lexical _"
+       (null? (call-with-warnings
+               (lambda ()
+                 (compile '(let ((_ (lambda (s)
+                                      (gettext s "my-domain"))))
+                             (format #t (_ "~A ~A!") "hello" "world"))
+                          #:opts %opts-w-format
+                          #:to 'assembly)))))
+
      (pass-if "non-literal format string using ngettext"
        (null? (call-with-warnings
                (lambda ()