Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private functions can't have contracts #34

Open
asianfilm opened this issue Jan 22, 2020 · 2 comments
Open

Private functions can't have contracts #34

asianfilm opened this issue Jan 22, 2020 · 2 comments

Comments

@asianfilm
Copy link

You can't specify a contract for a private function.

For example:

defmodule Test do
  use Norm

  @contract public() :: :ok
  def public(), do: :ok

  @contract private() :: :ok
  defp private(), do: ok
end

Gives the error:

** (ArgumentError) contract for undefined function private/0

There's a strong argument that only contracts at a module's boundaries should have contracts (or tests). But the author has stated: "My goal is to build a system that allows you to validate any elixir data at any point in your stack."

My workaround for now is to make all my functions public.

PS: Take my flood of issues as evidence that I'm loving the library.

@keathley
Copy link
Member

I think there's a case to be made for supporting contracts on defp. I'm certainly not opposed to it.

@wojtekmach
Copy link
Contributor

In #29 we introduce foundation for contract reflection. The plan for reflection is to start it as private API, if it becomes public the question would be whether a contract for a private function should be public. I can see both sides of this: if reflection would be used as just a list of contracts (to e.g. re-use a contract elsewhere) then +1 for this; on the other hand if reflection would be used to see capabilities of the given module (what functions it has and what they require/provide) then imho it should be private, perhaps with a @contractp.

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

No branches or pull requests

3 participants