diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-27 11:26:28 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-27 17:46:52 +0000 |
commit | 8b26228473c7910d5899c31a0db9920a9184db4d (patch) | |
tree | 671ecc3fa638283d37fc75dc52b15cf64589dbbe | |
parent | 5f3479a49388847ecd3ff0be8aea8fa276311e61 (diff) | |
download | lace-8b26228473c7910d5899c31a0db9920a9184db4d.tar.gz |
lace.builtin.define: Clarify unknown control type error
There was much confusion when trying to work out why
define foo [bar] did not work.
The fact that [bar] expands to `define $RANDOM bar` and the [bar] token is
replaced by $RANDOM, which isn't a control type and is not defined until
runtime, so can't work.
Pragmatically this only prevents you using define to create an alias for
another command, which is of debatable utility.
-rw-r--r-- | lib/lace/builtin.lua | 3 | ||||
-rw-r--r-- | test/test-lace.builtin.lua | 2 | ||||
-rw-r--r-- | test/test-lace.compiler.lua | 2 |
3 files changed, 4 insertions, 3 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua index b76295c..bfc1207 100644 --- a/lib/lace/builtin.lua +++ b/lib/lace/builtin.lua @@ -277,7 +277,8 @@ function builtin.define(compcontext, define, name, controltype, ...) local controlfn = _controlfn(compcontext, controltype) if not controlfn then - return err.error("Unknown control type: " .. controltype, {3}) + emsg = "%s's second parameter (%s) must be a control type such as anyof" + return err.error(emsg:format(define, controltype), {3}) end local ctrltab, msg = controlfn(compcontext, controltype, ...) diff --git a/test/test-lace.builtin.lua b/test/test-lace.builtin.lua index b2eafde..927acb1 100644 --- a/test/test-lace.builtin.lua +++ b/test/test-lace.builtin.lua @@ -203,7 +203,7 @@ function suite.compile_builtin_define_badctype() assert(cmdtab == false, "Internal errors should return false") assert(type(msg) == "table", "Internal errors should return tables") assert(type(msg.msg) == "string", "Internal errors should have string messages") - assert(msg.msg:match("Unknown control"), "Expected error should mention unknown control type") + assert(msg.msg:match("must be a control type"), "Expected error should mention unknown control type") end function suite.compile_builtin_define_ctype_errors() diff --git a/test/test-lace.compiler.lua b/test/test-lace.compiler.lua index d6a26a2..5c2f5c2 100644 --- a/test/test-lace.compiler.lua +++ b/test/test-lace.compiler.lua @@ -341,7 +341,7 @@ function suite.error_in_define4() assert(type(msg) == "string", "Compilation errors should be strings") assert(msg:find("\n"), "Compilation errors are multiline") local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") - assert(line1:find("Unknown control"), "The first line must mention the error") + assert(line1:find("must be a control type"), "The first line must mention the error") assert(line2 == "real-errorindefine4 :: 3", "The second line is where the error happened") assert(line3 == "define fish does_not_exist", "The third line is the original line") assert(line4 == " ^^^^^^^^^^^^^^", "The fourth line highlights relevant words") |