Qqwy / elixir-type_check

TypeCheck: Fast and flexible runtime type-checking for your Elixir projects.
MIT License
521 stars 25 forks source link

Fully qualified function names in `@type!` guards #147

Closed lbueso closed 2 years ago

lbueso commented 2 years ago

When defining a guarded type with @type!, if the type is used in an @spec! in other module, the functions used in the guard need to be fully qualified. This generates a compilation error:

defmodule A do
  use TypeCheck

  @type! f :: integer() when is_f(f)

  def is_f(_f), do: true
end

defmodule B do
  use TypeCheck

  @spec! f() :: A.f()
  def f(), do: 1
end
== Compilation error in file lib/examples.ex ==
** (CompileError) lib/type_check/spec.ex:4: undefined function is_f/1 (expected B to define such a function or for it to be imported, but none are available)

But this doesn't:

defmodule A do
  use TypeCheck

  @type! f :: integer() when A.is_f(f)

  def is_f(_f), do: true
end

defmodule B do
  use TypeCheck

  @spec! f() :: A.f()
  def f(), do: 1
end

If the @spec! that uses the type is defined in the same module that the guarded @type! this error doesn't appear.

Qqwy commented 2 years ago

The fix is part of the now-published release v0.12.4.