Disallow &key in macros

This commit is contained in:
Ryan Gonzalez 2016-07-07 11:24:04 -05:00
parent 7ee7428870
commit d384580de1
2 changed files with 8 additions and 2 deletions

View File

@ -2428,7 +2428,7 @@ class HyASTCompiler(object):
raise HyTypeError(name, ("received a `%s' instead of a symbol "
"for macro name" % type(name).__name__))
name = HyString(name).replace(name)
for kw in ("&kwonly", "&kwargs"):
for kw in ("&kwonly", "&kwargs", "&key"):
if kw in expression[0]:
raise HyTypeError(name, "macros cannot use %s" % kw)
new_expression = HyExpression([

View File

@ -51,7 +51,7 @@
(foo x y))
(defn test-macro-kw []
"NATIVE: test that an error is raised when &kwonly or &kwargs is used in a macro"
"NATIVE: test that an error is raised when &kwonly, &kwargs, or &key is used in a macro"
(try
(eval '(defmacro f [&kwonly a b]))
(except [e HyTypeError]
@ -62,6 +62,12 @@
(eval '(defmacro f [&kwargs kw]))
(except [e HyTypeError]
(assert (= e.message "macros cannot use &kwargs")))
(else (assert false)))
(try
(eval '(defmacro f [&key {"kw" "xyz"}]))
(except [e HyTypeError]
(assert (= e.message "macros cannot use &key")))
(else (assert false))))
(defn test-fn-calling-macro []