|
69 | 69 | :protocol-duped-method true
|
70 | 70 | :protocol-multiple-impls true
|
71 | 71 | :single-segment-namespace true
|
72 |
| - :munged-namespace true}) |
| 72 | + :munged-namespace true |
| 73 | + :ns-var-clash true}) |
73 | 74 |
|
74 | 75 | (def js-reserved
|
75 | 76 | #{"abstract" "boolean" "break" "byte" "case"
|
|
209 | 210 | (str "Namespace " name " contains a reserved JavaScript keyword,"
|
210 | 211 | " the corresponding Google Closure namespace will be munged to " munged)))
|
211 | 212 |
|
| 213 | +(defmethod error-message :ns-var-clash |
| 214 | + [warning-type {:keys [ns var] :as info}] |
| 215 | + (str "Namespace " ns " clashes with var " var)) |
| 216 | + |
212 | 217 | (defn ^:private default-warning-handler [warning-type env extra]
|
213 | 218 | (when (warning-type *cljs-warnings*)
|
214 | 219 | (when-let [s (error-message warning-type extra)]
|
|
770 | 775 | protocol (-> sym meta :protocol)
|
771 | 776 | dynamic (-> sym meta :dynamic)
|
772 | 777 | ns-name (-> env :ns :name)
|
773 |
| - locals (:locals env)] |
| 778 | + locals (:locals env) |
| 779 | + clash-ns (symbol (str ns-name "." sym))] |
| 780 | + (when (get-in @env/*compiler* [::namespaces clash-ns]) |
| 781 | + (warning :ns-var-clash env |
| 782 | + {:ns (symbol (str ns-name "." sym)) |
| 783 | + :var (symbol (str ns-name) (str sym))})) |
774 | 784 | (when (namespace sym)
|
775 | 785 | (throw (error env "Can't def ns-qualified name")))
|
776 | 786 | (when-let [doc (:doc args)]
|
|
1406 | 1416 | (update-in indexed [:require-macros] (fnil into []) require-specs))
|
1407 | 1417 | args)))
|
1408 | 1418 |
|
| 1419 | +(defn find-def-clash [env ns segments] |
| 1420 | + (let [to-check (map (fn [xs] |
| 1421 | + [(symbol (string/join "." (butlast xs))) |
| 1422 | + (symbol (last xs))]) |
| 1423 | + (drop 2 (reductions conj [] segments)))] |
| 1424 | + (doseq [[clash-ns name] to-check] |
| 1425 | + (when (get-in @env/*compiler* [::namespaces clash-ns :defs name]) |
| 1426 | + (warning :ns-var-clash env |
| 1427 | + {:ns ns |
| 1428 | + :var (symbol (str clash-ns) (str name))}))))) |
| 1429 | + |
1409 | 1430 | (defmethod parse 'ns
|
1410 | 1431 | [_ env [_ name & args :as form] _ opts]
|
1411 | 1432 | (when-not (symbol? name)
|
|
1414 | 1435 | (when (= 1 (count segments))
|
1415 | 1436 | (warning :single-segment-namespace env {:name name}))
|
1416 | 1437 | (when (some js-reserved segments)
|
1417 |
| - (warning :munged-namespace env {:name name}))) |
| 1438 | + (warning :munged-namespace env {:name name})) |
| 1439 | + (find-def-clash env name segments)) |
1418 | 1440 | (let [docstring (if (string? (first args)) (first args))
|
1419 | 1441 | mdocstr (-> name meta :doc)
|
1420 | 1442 | args (if docstring (next args) args)
|
|
0 commit comments