diff options
author | Eduardo Julian | 2016-09-24 17:01:38 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-09-24 17:01:38 -0400 |
commit | 24f4c13d903a2526b5b6282bec5d451c009e2baf (patch) | |
tree | c78a0794e6b464467dcb8e1c57a7321a0906541d | |
parent | a934596e2944e95b688873a10426399ab0e706dc (diff) |
- Fixed a bug that allowed modules to refer to definitions of other already-compiled modules without these being imported.
-rw-r--r-- | src/lux/analyser/lux.clj | 4 | ||||
-rw-r--r-- | src/lux/analyser/module.clj | 55 | ||||
-rw-r--r-- | src/lux/base.clj | 2 |
3 files changed, 37 insertions, 24 deletions
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj index c50f26437..b4f87f140 100644 --- a/src/lux/analyser/lux.clj +++ b/src/lux/analyser/lux.clj @@ -268,14 +268,14 @@ (defn ^:private analyse-global [analyse exo-type module name] (|do [[[r-module r-name] [endo-type ?meta ?value]] (&&module/find-def module name) + ;; This is a small shortcut to optimize analysis of typing code. _ (if (and (clojure.lang.Util/identical &type/Type endo-type) (clojure.lang.Util/identical &type/Type exo-type)) (return nil) (&type/check exo-type endo-type)) _cursor &/cursor] (return (&/|list (&&/|meta endo-type _cursor - (&&/$var (&/$Global (&/T [r-module r-name]))) - ))))) + (&&/$var (&/$Global (&/T [r-module r-name])))))))) (defn ^:private analyse-local [analyse exo-type name] (fn [state] diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj index f35334399..ead4ffc67 100644 --- a/src/lux/analyser/module.clj +++ b/src/lux/analyser/module.clj @@ -159,31 +159,44 @@ nil)))) )) +(defn ^:private imports? [state imported-module source-module] + (->> state + (&/get$ &/$modules) + (&/|get source-module) + (&/get$ $imports) + (&/|any? (partial = imported-module)))) + (defn find-def [module name] (|do [current-module &/get-module-name] (fn [state] - (if-let [$module (->> state (&/get$ &/$modules) (&/|get module))] - (if-let [$def (->> $module (&/get$ $defs) (&/|get name))] - (|let [[?type ?meta ?value] $def] - (if (.equals ^Object current-module module) - (|case (&meta/meta-get &meta/alias-tag ?meta) - (&/$Some (&/$IdentM [?r-module ?r-name])) - ((find-def ?r-module ?r-name) - state) - - _ - (return* state (&/T [(&/T [module name]) $def]))) - (|case (&meta/meta-get &meta/export?-tag ?meta) - (&/$Some (&/$BoolM true)) - (return* state (&/T [(&/T [module name]) $def])) - - _ - ((&/fail-with-loc (str "[Analyser Error] Can't use unexported definition: " (str module &/+name-separator+ name))) - state)))) - ((&/fail-with-loc (str "[Analyser Error] Definition does not exist: " (str module &/+name-separator+ name))) + (if (or (= "lux" module) + (= current-module module) + (imports? state module current-module)) + (if-let [$module (->> state (&/get$ &/$modules) (&/|get module))] + (if-let [$def (->> $module (&/get$ $defs) (&/|get name))] + (|let [[?type ?meta ?value] $def] + (if (.equals ^Object current-module module) + (|case (&meta/meta-get &meta/alias-tag ?meta) + (&/$Some (&/$IdentM [?r-module ?r-name])) + ((find-def ?r-module ?r-name) + state) + + _ + (return* state (&/T [(&/T [module name]) $def]))) + (|case (&meta/meta-get &meta/export?-tag ?meta) + (&/$Some (&/$BoolM true)) + (return* state (&/T [(&/T [module name]) $def])) + + _ + ((&/fail-with-loc (str "[Analyser Error] Can't use unexported definition: " (str module &/+name-separator+ name))) + state)))) + ((&/fail-with-loc (str "[Analyser Error] Definition does not exist: " (str module &/+name-separator+ name))) + state)) + ((&/fail-with-loc (str "[Analyser Error] Module doesn't exist: " module)) state)) - ((&/fail-with-loc (str "[Analyser Error] Module doesn't exist: " module)) - state))))) + ((&/fail-with-loc (str "[Analyser Error] Unknown module: " module)) + state)) + ))) (defn ensure-type-def [def-data] "(-> DefData (Lux Type))" diff --git a/src/lux/base.clj b/src/lux/base.clj index b5bd4e732..3c4438c63 100644 --- a/src/lux/base.clj +++ b/src/lux/base.clj @@ -1244,7 +1244,7 @@ <default> ($Cons x xs*) - (<op> (p x) (|every? p xs*)))) + (<op> (p x) (<name> p xs*)))) |every? true and |any? false or) |