(ns ^:typed.clojure com.tailrecursion.blacktide.compiler.errors
"Source locations and structured errors shared by syntax analysis and lowering.
DSL markers obey the same Var visibility rules as other source forms."
(:require [com.tailrecursion.nanopass :as np]
[com.tailrecursion.blacktide.compiler.languages :as l]
[typed.clojure :as-alias t]))
(np/defpass site {:from [l/Bound Raw] :to [l/Bound Site] :args [l/Bound-Site] :body true}
[parent form]
((fn ^{::t/- [t/Any t/Any t/Any :-> l/Bound-Site]} location [file line column]
{:form form :file (if (string? file) file (:file parent))
:line (if (integer? line) line (:line parent))
:column (if (integer? column) column (:column parent))})
(:file (meta form)) (:line (meta form)) (:column (meta form))))
(np/defpass fail
{:from [l/Bound Site] :to t/Nothing :args [t/Kw t/Str (t/Map t/Kw t/Any)] :body true}
[kind message details site]
(throw (ex-info message (merge site details {:kind kind}))))
(np/defpass check-visibility
{:from [l/Bound Site] :to nil :args [t/AnyVar] :body true}
[v site]
;; The public Var field is authoritative; :ns metadata can be changed.
(when (and (not (.isPublic ^clojure.lang.Var v))
(not= *ns* (clojure.lang.Reflector/getInstanceField v "ns")))
(fail :private-var "Cannot access a private Var from another namespace" {:binding (.toSymbol ^clojure.lang.Var v)} site)))