Merge pull request #1657 from Kodiologist/no-empty-exprs
Make empty expressions illegal at the top level
This commit is contained in:
commit
d9fa039252
7
NEWS.rst
7
NEWS.rst
@ -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
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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*)")
|
||||||
|
@ -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)))
|
||||||
|
Loading…
Reference in New Issue
Block a user