From b86dd1befcba1bbdeb3eef8d556941f22613f7d6 Mon Sep 17 00:00:00 2001 From: Roman Bataev Date: Tue, 13 Mar 2018 21:01:06 -0700 Subject: [PATCH] Warn on duplicate defs --- core/ns.go | 3 +++ tests/linter/duplicate-def/input.clj | 11 +++++++++++ tests/linter/duplicate-def/output.txt | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 tests/linter/duplicate-def/input.clj create mode 100644 tests/linter/duplicate-def/output.txt diff --git a/core/ns.go b/core/ns.go index 79c9e8ed7..d916b2676 100644 --- a/core/ns.go +++ b/core/ns.go @@ -107,6 +107,9 @@ func (ns *Namespace) Intern(sym Symbol) *Var { panic(RT.NewErrorWithPos(fmt.Sprintf("WARNING: %s already refers to: %s in namespace %s", sym.ToString(false), existingVar.ToString(false), ns.ToString(false)), sym.GetInfo().Pos())) } + if LINTER_MODE && existingVar.expr != nil && !existingVar.ns.Name.Equals(SYMBOLS.joker_core) { + printParseWarning(sym.GetInfo().Pos(), "Duplicate def of "+existingVar.ToString(false)) + } return existingVar } diff --git a/tests/linter/duplicate-def/input.clj b/tests/linter/duplicate-def/input.clj new file mode 100644 index 000000000..344a838f4 --- /dev/null +++ b/tests/linter/duplicate-def/input.clj @@ -0,0 +1,11 @@ +(def b) +(def b 1) + +(declare f) +(defn f []) + +(def a 1) +(def a 2) + +(defn f1 []) +(defn f1 [a]) diff --git a/tests/linter/duplicate-def/output.txt b/tests/linter/duplicate-def/output.txt new file mode 100644 index 000000000..68876a912 --- /dev/null +++ b/tests/linter/duplicate-def/output.txt @@ -0,0 +1,2 @@ +tests/linter/duplicate-def/input.clj:8:6: Parse warning: Duplicate def of #'user/a +tests/linter/duplicate-def/input.clj:11:7: Parse warning: Duplicate def of #'user/f1