Merge pull request #1657 from Kodiologist/no-empty-exprs

Make empty expressions illegal at the top level
This commit is contained in:
Kodi Arfer 2018-07-24 09:15:27 -07:00 committed by GitHub
commit d9fa039252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 7 deletions

View File

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

View File

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

View File

@ -67,6 +67,12 @@ def test_ast_bad_type():
pass 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(): def test_ast_bad_if():
"Make sure AST can't compile invalid if*" "Make sure AST can't compile invalid if*"
cant_compile("(if*)") cant_compile("(if*)")

View File

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