Skip to content

Commit

Permalink
Warn on duplicate defs
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed Mar 14, 2018
1 parent d567606 commit b86dd1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions tests/linter/duplicate-def/input.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(def b)
(def b 1)

(declare f)
(defn f [])

(def a 1)
(def a 2)

(defn f1 [])
(defn f1 [a])
2 changes: 2 additions & 0 deletions tests/linter/duplicate-def/output.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b86dd1b

Please sign in to comment.