# Testing Private Functions

**URL:** <https://forum.elixirforum.com/t/testing-private-functions/74605>\
**Category:** Discussions\
**Tags:** learning-elixir\
**Created:** [March 11, 2026, 6:45pm UTC](https://forum.elixirforum.com/t/testing-private-functions/74605 "2026-03-11T18:45:34Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![Asd](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Asd](https://forum.elixirforum.com/u/Asd)\
**Post date:** [March 12, 2026, 3:07pm UTC](https://forum.elixirforum.com/t/testing-private-functions/74605/25 "2026-03-12T15:07:29Z")

</div>

> [@hauleth](#):
>
> You are confusing upcoming Elixir gradual-type system and [JIT type tracking](https://www.erlang.org/blog/type-based-optimizations-in-the-jit/)

Yeah, I misunderstood what you said.

> [@hauleth](#):
>
> Compiler need to keep guards in both functions, as it do not know if `bar/1` will be called only with integer

That’s true, but you are one step away from overcoming this problem, because it is always possible to change one public function into one public function and the private function clone, like this:

```elixir
defmodule Foo do
  def foo(a, b) when is_integer(a) and is_integer(b), do: a + bar_in_foo(b)

  def bar(b) when is_integer(b), do: b + 1

  defp bar_in_foo(b) when is_integer(b), do: b + 1
end

```

Every compiler can do this automatically and this optimization is called “speculative specialization” and while it increases the module size, it is fairly cheap in all the BEAM languages and can be applied almost everywhere

---

_[View the full topic](https://forum.elixirforum.com/t/testing-private-functions/74605)._
