aboutsummaryrefslogtreecommitdiffstats
path: root/core/base/match.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-20 20:07:37 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-20 20:08:25 +0000
commit04eb8afc8367e51c15c507740b2c55fce2569b0d (patch)
tree01c5a53fbcd72d9a05009792126af5c54c8486ae /core/base/match.moon
parentdocs/index: mention license + repo (diff)
downloadalive-04eb8afc8367e51c15c507740b2c55fce2569b0d.tar.gz
alive-04eb8afc8367e51c15c507740b2c55fce2569b0d.zip
language Error tracking
Close #3
Diffstat (limited to 'core/base/match.moon')
-rw-r--r--core/base/match.moon7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/base/match.moon b/core/base/match.moon
index a20bcdc..cb82ac4 100644
--- a/core/base/match.moon
+++ b/core/base/match.moon
@@ -2,6 +2,7 @@
-- Utilities for matching `Result` types.
--
-- @module match
+import Error from require 'core.error'
unpack or= table.unpack
class Pattern
@@ -39,11 +40,11 @@ class Pattern
matched = while @matches results[1]
table.remove results, 1
- assert @opt or #matched > 0, "expected at least one argument for spread"
+ assert @opt or #matched > 0, Error 'argument', "expected at least one argument for spread"
matched
else
matches = @matches results[1]
- assert @opt or matches, "couldn't match argument #{results[1]} as #{@}"
+ assert @opt or matches, Error 'argument', "argument #{results[1].value} incompatible with expected type #{@}"
if matches then table.remove results, 1
__tostring: =>
@@ -84,7 +85,7 @@ match = (pattern, inputs) ->
pattern = rest
Pattern pat
values = [p\match inputs for p in *patterns]
- assert #inputs == 0, "#{#inputs} extra arguments given!"
+ assert #inputs == 0, Error 'argument', "#{#inputs} extra arguments given!"
values
{