From dab48cc567f931b275ad647db1e47135b63c6675 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 2 Mar 2012 17:46:28 +0100 Subject: [PATCH] tweaks to -Wformat's gettext detection * module/language/tree-il/analyze.scm (proc-ref?): Change to use less false-if-exception and more variable-bound?. If a variable is present in the local module but not bound, assume that it is gettext if it has the right name. This is to allow for (define _ gettext). * test-suite/tests/tree-il.test ("warnings"): Update (_ "foo") example. --- module/language/tree-il/analyze.scm | 18 +++++++++--------- test-suite/tests/tree-il.test | 21 +++++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm index 5f995b68d..1fd8d584d 100644 --- a/module/language/tree-il/analyze.scm +++ b/module/language/tree-il/analyze.scm @@ -1352,16 +1352,16 @@ accurate information is missing from a given `tree-il' element." resort, return #t when EXP refers to the global variable SPECIAL-NAME." (match exp (($ _ name) - (let ((var (false-if-exception (module-variable env name)))) - (if var - (eq? (false-if-exception (variable-ref var)) ; VAR may be unbound - proc) - (eq? name special-name)))) ; special hack to support local aliases + (let ((var (module-variable env name))) + (if (and var (variable-bound? var)) + (eq? (variable-ref var) proc) + (eq? name special-name)))) ; special hack to support local aliases (($ _ module name public?) - (let ((m (false-if-exception (if public? - (resolve-interface module) - (resolve-module module))))) - (and m (eq? (false-if-exception (module-ref module name)) proc)))) + (let* ((mod (if public? + (false-if-exception (resolve-interface module)) + (resolve-module module #:ensure? #f))) + (var (and mod (module-variable mod name)))) + (and var (variable-bound? var) (eq? (variable-ref var) proc)))) (_ #f))) (define gettext? (cut proc-ref? <> gettext '_ <>)) diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test index b47528e35..3d5989e06 100644 --- a/test-suite/tests/tree-il.test +++ b/test-suite/tests/tree-il.test @@ -2221,18 +2221,15 @@ #:opts %opts-w-format #:to 'assembly))))) - (pass-if "non-literal format string with forward declaration" - (let ((w (call-with-warnings - (lambda () - (compile '(begin - (define (foo) - (format #t (_ "~A ~A!") "hello" "world")) - (define _ bar)) - #:opts %opts-w-format - #:to 'assembly))))) - (and (= (length w) 1) - (number? (string-contains (car w) - "non-literal format string"))))) + (pass-if "non-literal format string with (define _ gettext)" + (null? (call-with-warnings + (lambda () + (compile '(begin + (define _ gettext) + (define (foo) + (format #t (_ "~A ~A!") "hello" "world"))) + #:opts %opts-w-format + #:to 'assembly))))) (pass-if "wrong format string" (let ((w (call-with-warnings