summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
Diffstat (limited to 'module')
-rw-r--r--module/ice-9/boot-9.scm3
-rw-r--r--module/language/tree-il/analyze.scm34
-rw-r--r--module/language/tree-il/compile-cps.scm1
-rw-r--r--module/system/base/message.scm9
4 files changed, 44 insertions, 3 deletions
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 6e44ce77b..77bb3ced7 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -3665,7 +3665,8 @@ but it fails to load."
(define %auto-compilation-options
;; Default `compile-file' option when auto-compiling.
- '(#:warnings (unbound-variable macro-use-before-definition arity-mismatch
+ '(#:warnings (unbound-variable shadowed-toplevel
+ macro-use-before-definition arity-mismatch
format duplicate-case-datum bad-case-datum)))
(define* (load-in-vicinity dir file-name #:optional reader)
diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm
index ff4b93d31..62632fd3c 100644
--- a/module/language/tree-il/analyze.scm
+++ b/module/language/tree-il/analyze.scm
@@ -1,6 +1,6 @@
;;; TREE-IL -> GLIL compiler
-;; Copyright (C) 2001, 2008-2014 Free Software Foundation, Inc.
+;; Copyright (C) 2001, 2008-2014, 2018 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,7 @@
analyze-tree
unused-variable-analysis
unused-toplevel-analysis
+ shadowed-toplevel-analysis
unbound-variable-analysis
macro-use-before-definition-analysis
arity-analysis
@@ -815,6 +816,37 @@ given `tree-il' element."
;;;
+;;; Shadowed top-level definition analysis.
+;;;
+
+(define shadowed-toplevel-analysis
+ ;; Report top-level definitions that shadow previous top-level
+ ;; definitions from the same compilation unit.
+ (make-tree-analysis
+ (lambda (x defs env locs)
+ ;; Going down into X.
+ (record-case x
+ ((<toplevel-define> name src)
+ (match (vhash-assq name defs)
+ ((_ . previous-definition)
+ (warning 'shadowed-toplevel src name
+ (toplevel-define-src previous-definition))
+ defs)
+ (#f
+ (vhash-consq name x defs))))
+ (else defs)))
+
+ (lambda (x defs env locs)
+ ;; Leaving X's scope.
+ defs)
+
+ (lambda (defs env)
+ #t)
+
+ vlist-null))
+
+
+;;;
;;; Unbound variable analysis.
;;;
diff --git a/module/language/tree-il/compile-cps.scm b/module/language/tree-il/compile-cps.scm
index 7672524c1..6c8884add 100644
--- a/module/language/tree-il/compile-cps.scm
+++ b/module/language/tree-il/compile-cps.scm
@@ -2319,6 +2319,7 @@ integer."
(define %warning-passes
`((unused-variable . ,unused-variable-analysis)
(unused-toplevel . ,unused-toplevel-analysis)
+ (shadowed-toplevel . ,shadowed-toplevel-analysis)
(unbound-variable . ,unbound-variable-analysis)
(macro-use-before-definition . ,macro-use-before-definition-analysis)
(arity-mismatch . ,arity-analysis)
diff --git a/module/system/base/message.scm b/module/system/base/message.scm
index 979291c1e..8559a8568 100644
--- a/module/system/base/message.scm
+++ b/module/system/base/message.scm
@@ -1,6 +1,6 @@
;;; User interface messages
-;; Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2010, 2011, 2012, 2018 Free Software Foundation, Inc.
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
@@ -109,6 +109,13 @@
(emit port "~A: warning: possibly unused local top-level variable `~A'~%"
loc name)))
+ (shadowed-toplevel
+ "report shadowed top-level variables"
+ ,(lambda (port loc name previous-loc)
+ (emit port "~A: warning: shadows previous definition of `~A' at ~A~%"
+ loc name
+ (location-string previous-loc))))
+
(unbound-variable
"report possibly unbound variables"
,(lambda (port loc name)