diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-20 20:07:37 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-20 20:08:25 +0000 |
| commit | 04eb8afc8367e51c15c507740b2c55fce2569b0d (patch) | |
| tree | 01c5a53fbcd72d9a05009792126af5c54c8486ae /core/base | |
| parent | docs/index: mention license + repo (diff) | |
| download | alive-04eb8afc8367e51c15c507740b2c55fce2569b0d.tar.gz alive-04eb8afc8367e51c15c507740b2c55fce2569b0d.zip | |
language Error tracking
Close #3
Diffstat (limited to 'core/base')
| -rw-r--r-- | core/base/init.moon | 4 | ||||
| -rw-r--r-- | core/base/match.moon | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/core/base/init.moon b/core/base/init.moon index 64b34f4..bb35140 100644 --- a/core/base/init.moon +++ b/core/base/init.moon @@ -12,6 +12,7 @@ -- @see match -- @see Value -- @see Result +-- @see Error import IO from require 'core.base.io' import Op from require 'core.base.op' @@ -21,6 +22,7 @@ import Input from require 'core.base.input' import match from require 'core.base.match' import Value from require 'core.value' import Result from require 'core.result' +import Error from require 'core.error' { :IO @@ -31,5 +33,5 @@ import Result from require 'core.result' :match -- redundant exports, to keep anything an extension might need in one import - :Value, :Result + :Value, :Result, :Error } 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 { |
