diff --git a/hy/compiler.py b/hy/compiler.py index 0969966..19e8bcb 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -503,10 +503,11 @@ class HyASTCompiler(object): compiled_value = self.compile(value) ret += compiled_value - # no unicode for py2 in ast names - keyword = str(expr[2:]) - if "-" in keyword and keyword != "-": - keyword = keyword.replace("-", "_") + keyword = expr[2:] + if not keyword: + raise HyTypeError(expr, "Can't call a function with the " + "empty keyword") + keyword = ast_str(keyword) keywords.append(asty.keyword( expr, arg=keyword, value=compiled_value.force_expr)) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index a4f39dd..89f8e5d 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -1232,11 +1232,7 @@ (assert (= : :)) (assert (keyword? :)) (assert (!= : ":")) - (assert (= (name :) "")) - - (defn f [&kwargs kwargs] - (list (.items kwargs))) - (assert (= (f : 3) [(, "" 3)]))) + (assert (= (name :) ""))) (defn test-nested-if [] diff --git a/tests/native_tests/mangling.hy b/tests/native_tests/mangling.hy index 5ddca3b..4351436 100644 --- a/tests/native_tests/mangling.hy +++ b/tests/native_tests/mangling.hy @@ -129,6 +129,27 @@ (assert (= hyx_Xplus_signX 3)))) +(defn test-keyword-args [] + + (defn f [a a-b foo? ☘] + [a a-b foo? ☘]) + (assert (= (f :foo? 3 :☘ 4 :a 1 :a-b 2) [1 2 3 4])) + (if PY3 + (assert (= (f :is_foo 3 :hyx_ΔshamrockΔ 4 :a 1 :a_b 2) [1 2 3 4])) + (assert (= (f :is_foo 3 :hyx_XshamrockX 4 :a 1 :a_b 2) [1 2 3 4]))) + + (defn g [&kwargs x] + x) + (setv sk (.format "hyx_{0}shamrock{0}" (if PY3 "Δ" "X"))) + (assert (= (g :foo? 3 :☘ 4 :a 1 :a-b 2) + {"a" 1 "a_b" 2 "is_foo" 3 sk 4})) + (if PY3 + (assert (= (g :is_foo 3 :hyx_ΔshamrockΔ 4 :a 1 :a_b 2) + {"a" 1 "a_b" 2 "is_foo" 3 sk 4})) + (assert (= (g :is_foo 3 :hyx_XshamrockX 4 :a 1 :a_b 2) + {"a" 1 "a_b" 2 "is_foo" 3 sk 4})))) + + (defn test-late-mangling [] ; Mangling should only happen during compilation. (assert (!= 'foo? 'is_foo))