Make empty expressions illegal at the top level

This commit is contained in:
Kodi Arfer 2018-07-24 08:59:52 -07:00
parent addf9c4a01
commit 03aafad657
4 changed files with 16 additions and 7 deletions

View File

@ -1,5 +1,12 @@
.. default-role:: code
Unreleased
==============================
Removals
------------------------------
* Empty expressions (`()`) are no longer legal at the top level.
0.15.0
==============================

View File

@ -1546,8 +1546,9 @@ class HyASTCompiler(object):
# Go through compile again if the type changed.
return self.compile(expression)
if expression == []:
return self.compile_atom(HyList().replace(expression))
if not expression:
raise HyTypeError(
expression, "empty expressions are not allowed at top level")
fn = expression[0]
func = None

View File

@ -67,6 +67,12 @@ def test_ast_bad_type():
pass
def test_empty_expr():
"Empty expressions should be illegal at the top level."
cant_compile("(print ())")
can_compile("(print '())")
def test_ast_bad_if():
"Make sure AST can't compile invalid if*"
cant_compile("(if*)")

View File

@ -1401,11 +1401,6 @@
(assert (= y [5])))
(defn test-empty-list []
"Evaluate an empty list to a []"
(assert (= () [])))
(defn test-string []
(assert (string? (string "a")))
(assert (string? (string 1)))