Disallow &key in macros
This commit is contained in:
parent
7ee7428870
commit
d384580de1
@ -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([
|
||||
|
@ -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 []
|
||||
|
Loading…
Reference in New Issue
Block a user