Skip to content

Commit 6ccfe53

Browse files
authored
Fix issue where AST could be generated twice, causing mismatches (#88)
* Fix issue where AST could be generated twice, causing mismatches * Satisfy the type checker
1 parent 4c5f561 commit 6ccfe53

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

basilisp/compiler.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,12 +1347,14 @@ def _collection_literal_ast(ctx: CompilerContext,
13471347
form: Iterable[LispForm]) -> Tuple[ASTStream, PyASTStream]:
13481348
"""Turn a collection literal of Lisp forms into Python AST nodes, filtering
13491349
out empty nodes."""
1350-
orig = seq(form) \
1351-
.map(lambda x: _to_ast(ctx, x)) \
1352-
.map(_nodes_and_exprl)
1353-
1354-
return (orig.flat_map(lambda x: x[0]).to_list(),
1355-
orig.flat_map(lambda x: x[1]).map(_unwrap_node).to_list())
1350+
deps: List[ASTNode] = []
1351+
nodes = []
1352+
for f in form:
1353+
depnodes, exprl = _nodes_and_exprl(_to_ast(ctx, f))
1354+
deps.extend(depnodes)
1355+
nodes.extend(_unwrap_nodes(exprl))
1356+
1357+
return deps, nodes
13561358

13571359

13581360
def _with_loc(f: ASTProcessor) -> ASTProcessor:

tests/compiler_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ def test_if(ns_var: Var):
273273
assert lcompile("(if nil :a :b)") == kw.keyword("b")
274274
assert lcompile("(if true (if false :a :c) :b)") == kw.keyword("c")
275275

276+
code = """
277+
(def f (fn* [s] s))
278+
279+
(f (if true \"YELLING\" \"whispering\"))
280+
"""
281+
assert "YELLING" == lcompile(code)
282+
276283

277284
def test_interop_call(ns_var: Var):
278285
assert lcompile('(. "ALL-UPPER" lower)') == "all-upper"

0 commit comments

Comments
 (0)