|
153 | 153 | :single-segment-namespace true |
154 | 154 | :munged-namespace true |
155 | 155 | :ns-var-clash true |
| 156 | + :non-dynamic-earmuffed-var true |
156 | 157 | :extend-type-invalid-method-shape true |
157 | 158 | :unsupported-js-module-type true |
158 | 159 | :unsupported-preprocess-value true |
|
467 | 468 | [warning-type {:keys [ns var] :as info}] |
468 | 469 | (str "Namespace " ns " clashes with var " var)) |
469 | 470 |
|
| 471 | +(defmethod error-message :non-dynamic-earmuffed-var |
| 472 | + [warning-type {:keys [var] :as info}] |
| 473 | + (str var " not declared dynamic and thus is not dynamically rebindable, but its name " |
| 474 | + "suggests otherwise. Please either indicate ^:dynamic " var " or change the name")) |
| 475 | + |
470 | 476 | (defmethod error-message :extend-type-invalid-method-shape |
471 | 477 | [warning-type {:keys [protocol method] :as info}] |
472 | 478 | (str "Bad extend-type method shape for protocol " protocol " method " method |
|
1602 | 1608 | :set (into #{} (map const-expr->constant-value (:items e))) |
1603 | 1609 | :vector (into [] (map const-expr->constant-value (:items e))))) |
1604 | 1610 |
|
| 1611 | +(defn- earmuffed? [sym] |
| 1612 | + (let [s (name sym)] |
| 1613 | + (and (> (count s) 2) |
| 1614 | + (string/starts-with? s "*") |
| 1615 | + (string/ends-with? s "*")))) |
| 1616 | + |
| 1617 | +(defn- core-ns? [ns-sym] |
| 1618 | + (let [s (name ns-sym)] |
| 1619 | + (and (not= 'cljs.user ns-sym) |
| 1620 | + (or (string/starts-with? s "cljs.") |
| 1621 | + (string/starts-with? s "clojure."))))) |
| 1622 | + |
1605 | 1623 | (defmethod parse 'def |
1606 | 1624 | [op env form _ _] |
1607 | 1625 | (when (> (count form) 4) |
|
1639 | 1657 | (when-some [doc (:doc args)] |
1640 | 1658 | (when-not (string? doc) |
1641 | 1659 | (throw (error env "Too many arguments to def")))) |
| 1660 | + (when (and (not dynamic) |
| 1661 | + (earmuffed? sym) |
| 1662 | + (not (core-ns? ns-name))) |
| 1663 | + (warning :non-dynamic-earmuffed-var env |
| 1664 | + {:var (str sym)})) |
1642 | 1665 | (when-some [v (get-in @env/*compiler* [::namespaces ns-name :defs sym])] |
1643 | 1666 | (when (and (not *allow-redef*) |
1644 | 1667 | (not (:declared v)) |
|
0 commit comments