1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 13:30:26 +02:00

Improve special-casing of _' in -Wformat'.

* 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.
This commit is contained in:
Ludovic Courtès 2012-05-12 15:31:28 +02:00
parent da874e5415
commit 4c98474782
2 changed files with 22 additions and 2 deletions

View 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 '_ <>))

View file

@ -1242,6 +1242,22 @@
#: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 ()