diff options
author | Eduardo Julian | 2022-07-10 18:25:57 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-07-10 18:25:57 -0400 |
commit | dec796a9838e39148c007f3f3d360964d7cb68de (patch) | |
tree | 6a009ec0046c237ead74f98983a8e63a870e1f5f /stdlib | |
parent | 1bbc4251230cee13d46df7b706859e834778aee0 (diff) |
Better error reporting when analyzing variants.
Diffstat (limited to '')
5 files changed, 29 insertions, 20 deletions
diff --git a/stdlib/source/documentation/lux/control/security/capability.lux b/stdlib/source/documentation/lux/control/security/capability.lux index 8d9c7f2ad..d328cabd3 100644 --- a/stdlib/source/documentation/lux/control/security/capability.lux +++ b/stdlib/source/documentation/lux/control/security/capability.lux @@ -20,9 +20,9 @@ "Applies a capability against its required input." [(use capability input)]) - ($.definition /.capability: + ($.definition /.capability "Defines a capability as a unique type, and a constructor for instances." - [(capability: (Can_Duplicate a) + [(capability (Can_Duplicate a) (can_duplicate a [a a])) (let [capability (can_duplicate diff --git a/stdlib/source/library/lux/control/security/capability.lux b/stdlib/source/library/lux/control/security/capability.lux index 24e627960..48323d842 100644 --- a/stdlib/source/library/lux/control/security/capability.lux +++ b/stdlib/source/library/lux/control/security/capability.lux @@ -26,14 +26,14 @@ (primitive .public (Capability brand input output) (-> input output) - (def .public (use capability input) + (def .public (use it input) (All (_ brand input output) (-> (Capability brand input output) input output)) - ((representation capability) input)) + ((representation it) input)) - (def .public capability: + (def .public capability (syntax (_ [[export_policy declaration [forger input output]] (|export|.parser (all <>.and @@ -45,20 +45,20 @@ .let [[name vars] declaration] g!brand (at ! each (|>> %.code code.text) (macro.symbol (format (%.symbol [this_module name])))) - .let [capability (` (..Capability (.Primitive (, g!brand)) (, input) (, output)))]] + .let [type (` (..Capability (.Primitive (, g!brand)) (, input) (, output)))]] (in (list (` (type (, export_policy) (, (|declaration|.format declaration)) - (, capability))) + (, type))) (` (def (, (code.local forger)) (All ((, g!_) (,* (list#each code.local vars))) (-> (-> (, input) (, output)) - (, capability))) + (, type))) (|>> as_expected))) )))))) - (def .public (async capability) + (def .public (async it) (All (_ brand input output) (-> (Capability brand input (IO output)) (Capability brand input (Async output)))) - (abstraction (|>> ((representation capability)) async.future))) + (abstraction (|>> ((representation it)) async.future))) ) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux index 2db7b161f..ec4a32d05 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux @@ -64,10 +64,18 @@ ["Expression" (%.code code)])))] [invalid_variant_type] - [cannot_analyse_variant] + [cannot_analyse_sum] [cannot_infer_sum] ) +(exception .public (cannot_analyse_variant [type Type + tag Symbol + code Code]) + (exception.report + (list ["Type" (%.type type)] + ["Tag" (%.symbol tag)] + ["Expression" (%.code code)]))) + (exception .public (cannot_repeat_slot [key Symbol record (List [Symbol Code])]) (exception.report @@ -104,7 +112,7 @@ (do [! ///.monad] [expectedT (///extension.lifted meta.expected_type) expectedT' (/type.check (check.clean (list) expectedT))] - (/.with_exception ..cannot_analyse_variant [expectedT' lefts right? valueC] + (/.with_exception ..cannot_analyse_sum [expectedT' lefts right? valueC] (case expectedT {.#Sum _} (|> (analyse archive valueC) @@ -184,7 +192,8 @@ (in (/.variant [lefts right? (|> valueA+ list.head maybe.trusted)]))) _ - (..sum analyse lefts right? archive valueC)))) + (/.with_exception ..cannot_analyse_variant [expectedT tag valueC] + (..sum analyse lefts right? archive valueC))))) (def (typed_product analyse expectedT archive members) (-> Phase Type Archive (List Code) (Operation Analysis)) diff --git a/stdlib/source/library/lux/world/db/jdbc.lux b/stdlib/source/library/lux/world/db/jdbc.lux index 955335715..4c215de63 100644 --- a/stdlib/source/library/lux/world/db/jdbc.lux +++ b/stdlib/source/library/lux/world/db/jdbc.lux @@ -12,7 +12,7 @@ [concurrency ["[0]" async (.only Async) (.use "[1]#[0]" monad)]] [security - ["!" capability (.only capability:)]]] + ["!" capability (.only capability)]]] [data ["[0]" product] [text @@ -66,17 +66,17 @@ #value input])) (with_template [<name> <forge> <output>] - [(capability: .public (<name> ! i) + [(capability .public (<name> ! i) (<forge> (Statement i) (! (Try <output>))))] [Can_Execute can_execute Nat] [Can_Insert can_insert (List ID)] ) -(capability: .public (Can_Query ! i o) +(capability .public (Can_Query ! i o) (can_query [(Statement i) (Output o)] (! (Try (List o))))) -(capability: .public (Can_Close !) +(capability .public (Can_Close !) (can_close Any (! (Try Any)))) (type .public (DB !) diff --git a/stdlib/source/test/lux/control/security/capability.lux b/stdlib/source/test/lux/control/security/capability.lux index d61e32bbe..ecc9d22ba 100644 --- a/stdlib/source/test/lux/control/security/capability.lux +++ b/stdlib/source/test/lux/control/security/capability.lux @@ -15,10 +15,10 @@ [\\library ["[0]" /]]) -(/.capability: (Can_Shift a) +(/.capability (Can_Shift a) (can_shift [a Nat] [a Nat])) -(/.capability: Can_IO +(/.capability Can_IO (can_io [] (IO Nat))) (def .public test @@ -31,7 +31,7 @@ pass_through (random.ascii 1)] (_.for [/.Capability] (all _.and - (_.coverage [/.capability: /.use] + (_.coverage [/.capability /.use] (let [capability (..can_shift (function (_ [no_op raw]) [no_op (n.+ shift raw)])) [untouched actual] (/.use capability [pass_through base])] |