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

Local parametrised types are broken #39

Open
turion opened this issue Dec 10, 2020 · 2 comments · May be fixed by #42
Open

Local parametrised types are broken #39

turion opened this issue Dec 10, 2020 · 2 comments · May be fixed by #42

Comments

@turion
Copy link
Contributor

turion commented Dec 10, 2020

defmodule Foo do
  @type t(elem) :: [elem]

  @spec mylength(t(term())) :: integer()

  def mylength(_) do
    23
  end
end
$ mix type
** (FunctionClauseError) no function clause matching in ExType.Typespec.eval_type/2    
    
    The following arguments were given to ExType.Typespec.eval_type/2:
    
        # 1
        %ExType.Type.Any{}
    
        # 2
        {Foo, %{elem: %ExType.Type.Any{}}}
    
    Attempted function clauses (showing 10 out of 57):
    
        def eval_type({:any, _, []}, _)
        def eval_type({:none, _, []}, _)
        def eval_type({:atom, _, []}, _)
        def eval_type({:map, _, []}, _)
        def eval_type({:pid, _, []}, _)
        def eval_type({:port, _, []}, _)
        def eval_type({:reference, _, []}, _)
        def eval_type({:struct, _, []}, _)
        def eval_type({:tuple, _, []}, _)
        def eval_type({:float, _, []}, _)
        ...
        (47 clauses not shown)
    
    lib/ex_type/typespec.ex:249: ExType.Typespec.eval_type/2
    lib/ex_type/typespec.ex:342: ExType.Typespec.eval_type/2
    (elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
    lib/ex_type/typespec.ex:666: anonymous fn/4 in ExType.Typespec.fetch_specs/3
    (elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
    lib/ex_type/typespec.ex:648: ExType.Typespec.fetch_specs/3
    lib/ex_type/custom_env.ex:154: ExType.CustomEnv.process_defs/5
    (elixir 1.10.4) lib/enum.ex:1400: anonymous fn/3 in Enum.map/2
@turion
Copy link
Contributor Author

turion commented Dec 10, 2020

When I inline t, it works:

defmodule Foo do
  @spec mylength([term()]) :: integer()

  def mylength(_) do
    23
  end
end
$ mix type
✅  Foo.mylength/1

@turion
Copy link
Contributor Author

turion commented Dec 10, 2020

The issue is probably in the handling of local types:

def eval_type({name, _meta, args}, {module, _} = context)

There, the type variable is evaluated to %Any{}, but it should really be a %SpecVariable{} "applied" to %Any{}! In fact, it seems %SpecVariable{} doesn't even have a context, maybe they should be closures? Or they should be evaluated correctly at least.

turion pushed a commit to turion/ex_type that referenced this issue Dec 10, 2020
turion pushed a commit to turion/ex_type that referenced this issue Dec 25, 2020
turion pushed a commit to turion/ex_type that referenced this issue Dec 26, 2020
turion pushed a commit to turion/ex_type that referenced this issue Feb 24, 2021
turion pushed a commit to turion/ex_type that referenced this issue Feb 24, 2021
@turion turion linked a pull request Feb 24, 2021 that will close this issue
turion pushed a commit to turion/ex_type that referenced this issue Feb 14, 2022
turion pushed a commit to turion/ex_type that referenced this issue Feb 14, 2022
turion pushed a commit to turion/ex_type that referenced this issue Mar 24, 2023
turion pushed a commit to turion/ex_type that referenced this issue Mar 24, 2023
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 a pull request may close this issue.

1 participant