Skip to content

Conversation

chrisrink10
Copy link
Member

@chrisrink10 chrisrink10 commented Jan 26, 2024

Add a compile-time warning for arity mismatches on function invocations. The warning is enabled by default (if the dev logger is enabled and configured for at least WARNING level logs).

In order to facilitate this work, we also had to change the computation of the Basilisp function arities attribute set. Previously this included only fixed arities (the argument count for each non-variadic function arity) and a :rest keyword if the function included a variadic arity. Now arities will include all fixed arities including the number of fixed (non-variadic) arguments to the varidic arity. This allows for more sophisticated warnings.

As part of this bill of work, it was also required to update partial to support computing a new set of arities for partial applications. functools.wraps copies all values from __dict__ to wrapped functions, so partials were appearing to have the same set of arities as their wrapped function which was never correct.

Fixes #671
Fixes #847

@chrisrink10 chrisrink10 force-pushed the feature/compile-time-arity-warnings branch from 5316647 to d3cb1ee Compare January 28, 2024 14:45
@chrisrink10 chrisrink10 force-pushed the feature/compile-time-arity-warnings branch from 9dff082 to 87719bf Compare January 29, 2024 00:31
@@ -43,3 +50,13 @@
PyCollectionForm = Union[dict, list, set, tuple]
ReaderForm = Union[LispForm, IRecord, ISeq, IType, PyCollectionForm]
SpecialForm = Union[llist.PersistentList, ISeq]


class BasilispFunction(Protocol):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically also IWithMeta but MyPy does not allow Protocols to inherit from non-Protocols and I don't want to mess with trying to change IWithMeta to a Protocol type now.

@@ -30,7 +30,7 @@ def pytest_collect_file(file_path: Path, path, parent):
"""Primary PyTest hook to identify Basilisp test files."""
if file_path.suffix == ".lpy":
if file_path.name.startswith("test_") or file_path.stem.endswith("_test"):
return BasilispFile.from_parent(parent, fspath=path, path=file_path)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was constantly hitting us with deprecation warnings on test runs.

@@ -3223,7 +3231,6 @@ def _interop_prop_to_py_ast(
assert node.op == NodeOp.HOST_FIELD

target_ast = gen_py_ast(ctx, node.target)
assert not target_ast.dependencies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this was here. The dependencies are passed on a couple lines down.

@chrisrink10 chrisrink10 marked this pull request as ready for review January 29, 2024 17:23
@chrisrink10 chrisrink10 merged commit 8b3a2da into main Jan 29, 2024
@chrisrink10 chrisrink10 deleted the feature/compile-time-arity-warnings branch January 29, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

partial does not update function attributes correctly Add a compiler warning for arity-mismatch on calls
1 participant