diff --git a/NEWS b/NEWS index 4c963f4..52aaa5a 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ Changes from 0.13.0 * Numeric literals are no longer parsed as symbols when followed by a dot and a symbol * Hy now respects the environment variable PYTHONDONTWRITEBYTECODE + * String literals should no longer be interpreted as special forms or macros Changes from 0.12.1 diff --git a/hy/compiler.py b/hy/compiler.py index d8d2fb3..da7e858 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -2004,7 +2004,7 @@ class HyASTCompiler(object): if isinstance(fn, HyKeyword): return self._compile_keyword_call(expression) - if isinstance(fn, HyString): + if isinstance(fn, HySymbol): ret = self.compile_atom(fn, expression) if ret: return ret @@ -2240,7 +2240,7 @@ class HyASTCompiler(object): args[i] = var = HySymbol(self.get_anon_var()) expression = HyExpression([ HyExpression([ - HyString("setv"), arg, var + HySymbol("setv"), arg, var ])] ) + expression expression = expression.replace(arg[0]) diff --git a/hy/macros.py b/hy/macros.py index 874c63a..22bda2e 100644 --- a/hy/macros.py +++ b/hy/macros.py @@ -3,7 +3,7 @@ # license. See the LICENSE. from inspect import getargspec, formatargspec -from hy.models import replace_hy_obj, HyExpression, HyString +from hy.models import replace_hy_obj, HyExpression, HySymbol from hy.errors import HyTypeError, HyMacroExpansionError @@ -179,7 +179,7 @@ def macroexpand_1(tree, compiler): opts = {} - if isinstance(fn, HyString): + if isinstance(fn, HySymbol): m = _hy_macros[compiler.module_name].get(fn) if m is None: m = _hy_macros[None].get(fn) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index b4f222d..cbef01e 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -169,6 +169,14 @@ (assert (= e.message "Can't assign or delete a HyInteger"))))) +(defn test-no-str-as-sym [] + "Don't treat strings as symbols in the calling position" + (with [(pytest.raises TypeError)] ("setv" True 3)) ; A special form + (with [(pytest.raises TypeError)] ("abs" -2)) ; A function + (with [(pytest.raises TypeError)] ("when" 1 2)) ; A macro + None) ; Avoid https://github.com/hylang/hy/issues/1320 + + (defn test-fn-corner-cases [] "NATIVE: tests that fn/defn handles corner cases gracefully" (try (eval '(fn "foo"))