diff --git a/hy/compiler.py b/hy/compiler.py index 99c36d1..677dab4 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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([ diff --git a/tests/native_tests/native_macros.hy b/tests/native_tests/native_macros.hy index 8c2f602..eca4538 100644 --- a/tests/native_tests/native_macros.hy +++ b/tests/native_tests/native_macros.hy @@ -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 []