From f9c3966e6598bb4fc5b0fa81cb8c01b4df9c4734 Mon Sep 17 00:00:00 2001 From: Adam Schwalm Date: Sat, 12 Sep 2015 21:57:47 -0500 Subject: [PATCH] Remove hard-coded references to 'fn' and 'setv' in errors --- hy/compiler.py | 6 ++++-- tests/native_tests/language.hy | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index 9bad831..f3cc9ac 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -1994,7 +1994,8 @@ class HyASTCompiler(object): expression.start_column) elif len(expression) % 2 != 0: raise HyTypeError(expression, - "setv needs an even number of arguments") + "`{}' needs an even number of arguments".format( + root)) else: result = Result() exprs = [] @@ -2152,7 +2153,8 @@ class HyASTCompiler(object): arglist = expression.pop(0) if not isinstance(arglist, HyList): raise HyTypeError(expression, - "First argument to (fn) must be a list") + "First argument to `{}' must be a list".format( + called_as)) (ret, args, defaults, stararg, kwonlyargs, kwonlydefaults, kwargs) = self._parse_lambda_list(arglist) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index e9dbc27..af03baf 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -75,18 +75,31 @@ (setv y 0 x 1 y x) (assert y) (try (eval '(setv a 1 b)) - (except [e [TypeError]] (assert (in "setv needs an even number of arguments" (str e)))))) + (except [e [TypeError]] (assert (in "`setv' needs an even number of arguments" (str e)))))) (defn test-fn-corner-cases [] "NATIVE: tests that fn/defn handles corner cases gracefully" (try (eval '(fn "foo")) - (except [e [Exception]] (assert (in "to (fn) must be a list" + (except [e [Exception]] (assert (in "to `fn' must be a list" (str e))))) (try (eval '(defn foo "foo")) (except [e [Exception]] (assert (in "takes a parameter list as second" (str e)))))) + +(defn test-alias-names-in-errors [] + "NATIVE: tests that native aliases show the correct names in errors" + (try (eval '(lambda)) + (except [e [Exception]] (assert (in "lambda" (str e))))) + (try (eval '(fn)) + (except [e [Exception]] (assert (in "fn" (str e))))) + (try (eval '(setv 1 2 3)) + (except [e [Exception]] (assert (in "setv" (str e))))) + (try (eval '(def 1 2 3)) + (except [e [Exception]] (assert (in "def" (str e)))))) + + (defn test-for-loop [] "NATIVE: test for loops" (setv count1 0 count2 0)