Merge pull request #936 from ALSchwalm/master

Remove hard-coded references to 'fn' and 'setv' in errors
This commit is contained in:
Abhishek L 2015-09-15 14:56:02 +05:30
commit 8be0e40c7a
2 changed files with 19 additions and 4 deletions

View File

@ -1994,7 +1994,8 @@ class HyASTCompiler(object):
expression.start_column) expression.start_column)
elif len(expression) % 2 != 0: elif len(expression) % 2 != 0:
raise HyTypeError(expression, raise HyTypeError(expression,
"setv needs an even number of arguments") "`{}' needs an even number of arguments".format(
root))
else: else:
result = Result() result = Result()
exprs = [] exprs = []
@ -2152,7 +2153,8 @@ class HyASTCompiler(object):
arglist = expression.pop(0) arglist = expression.pop(0)
if not isinstance(arglist, HyList): if not isinstance(arglist, HyList):
raise HyTypeError(expression, 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, (ret, args, defaults, stararg,
kwonlyargs, kwonlydefaults, kwargs) = self._parse_lambda_list(arglist) kwonlyargs, kwonlydefaults, kwargs) = self._parse_lambda_list(arglist)

View File

@ -75,18 +75,31 @@
(setv y 0 x 1 y x) (setv y 0 x 1 y x)
(assert y) (assert y)
(try (eval '(setv a 1 b)) (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 [] (defn test-fn-corner-cases []
"NATIVE: tests that fn/defn handles corner cases gracefully" "NATIVE: tests that fn/defn handles corner cases gracefully"
(try (eval '(fn "foo")) (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))))) (str e)))))
(try (eval '(defn foo "foo")) (try (eval '(defn foo "foo"))
(except [e [Exception]] (except [e [Exception]]
(assert (in "takes a parameter list as second" (str e)))))) (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 [] (defn test-for-loop []
"NATIVE: test for loops" "NATIVE: test for loops"
(setv count1 0 count2 0) (setv count1 0 count2 0)