Skip to content

Commit

Permalink
Fix a bug with variadic function arity validation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrink10 committed May 28, 2020
1 parent 84f8f87 commit fd2a969
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
7 changes: 0 additions & 7 deletions src/basilisp/lang/compiler/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,13 +1917,6 @@ def _fn_ast( # pylint: disable=too-many-branches
fixed_arity_for_variadic: Optional[int] = None
num_variadic = 0
for arity in arities:
if fixed_arity_for_variadic is not None:
if arity.fixed_arity >= fixed_arity_for_variadic:
raise AnalyzerException(
"fn may not have a method with fixed arity greater than "
"fixed arity of variadic function",
form=arity.form,
)
if arity.is_variadic:
if num_variadic > 0:
raise AnalyzerException(
Expand Down
26 changes: 17 additions & 9 deletions tests/basilisp/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,18 +2606,26 @@ def test_multi_arity_fn_cannot_have_two_variadic_methods(
with pytest.raises(compiler.CompilerException):
lcompile(code)

@pytest.mark.parametrize(
"code",
[
"""
(def f
(fn* f
([s] (concat [s] :one-arg))
([& args] (concat [:rest-params] args))))""",
"""
(def f
(fn* f
([& args] (concat [:rest-params] args))
([s] (concat [s] :one-arg))))""",
],
)
def test_variadic_method_cannot_have_lower_fixed_arity_than_other_methods(
self, lcompile: CompileFn
self, lcompile: CompileFn, code: str
):
with pytest.raises(compiler.CompilerException):
lcompile(
"""
(def f
(fn* f
([s] (concat [s] :one-arg))
([& args] (concat [:rest-params] args))))
"""
)
lcompile(code)

def test_multi_arity_fn_dispatches_properly(
self, lcompile: CompileFn, ns: runtime.Namespace
Expand Down

0 comments on commit fd2a969

Please sign in to comment.