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

Support inline modules #23

Open
turion opened this issue Dec 8, 2020 · 1 comment · May be fixed by #24
Open

Support inline modules #23

turion opened this issue Dec 8, 2020 · 1 comment · May be fixed by #24

Comments

@turion
Copy link
Contributor

turion commented Dec 8, 2020

Consider this minimal example:

defmodule Foo do
  defmodule Bar do
    defstruct [:bar]
  end

  @spec hello(%Bar{}) :: :world
  def hello(_) do
    :world
  end
end
$ mix type
==> ex_type
Compiling 2 files (.ex)
✅  Foo.hello/1
** (CompileError) lib/foo.ex:6: Bar.__struct__/0 is undefined, cannot expand struct Bar. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
    (elixir 1.10.4) lib/kernel/typespec.ex:549: Kernel.Typespec.typespec/4
    (stdlib 3.12) lists.erl:1354: :lists.mapfoldl/3
    (elixir 1.10.4) lib/kernel/typespec.ex:950: Kernel.Typespec.fn_args/5
    (elixir 1.10.4) lib/kernel/typespec.ex:936: Kernel.Typespec.fn_args/6
    (elixir 1.10.4) lib/kernel/typespec.ex:377: Kernel.Typespec.translate_spec/8
    (stdlib 3.12) lists.erl:1354: :lists.mapfoldl/3
    (elixir 1.10.4) lib/kernel/typespec.ex:229: Kernel.Typespec.translate_typespecs_for_module/2

I'll try and submit a PR.

@turion
Copy link
Contributor Author

turion commented Dec 8, 2020

Here is a more sensible program that works as intended and shows the same error:

defmodule Foo do
  defmodule Bar do
    @enforce_keys [:bar]
    defstruct @enforce_keys

    @type t(bar) :: %Bar{
      bar: bar
    }
  end

  @spec get_bar(Bar.t(bar)) :: bar when bar: any()
  def get_bar(%Bar{bar: bar}) do
    bar
  end
end

turion pushed a commit to turion/ex_type that referenced this issue Dec 8, 2020
turion pushed a commit to turion/ex_type that referenced this issue Dec 8, 2020
@turion turion linked a pull request Dec 8, 2020 that will close this issue
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 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 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 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 Feb 14, 2022
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