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

Handle custom typespec rewrites #4

Open
sitch opened this issue Dec 1, 2020 · 0 comments
Open

Handle custom typespec rewrites #4

sitch opened this issue Dec 1, 2020 · 0 comments

Comments

@sitch
Copy link

sitch commented Dec 1, 2020

For the struct definition:

  defstruct accounts: [], item: nil, numbers: [], request_id: nil

  @type t :: %__MODULE__{
          accounts: [Plaid.Accounts.Account.t()],
          item: Plaid.Item.t(),
          numbers: %{
            ach: [Plaid.Auth.Numbers.ACH.t()],
            eft: [Plaid.Auth.Numbers.EFT.t()],
            international: [Plaid.Auth.Numbers.International.t()],
            bacs: [Plaid.Auth.Numbers.BACS.t()]
          },
          request_id: String.t()
        }

Getting this error from Form.Typespecs.compile(Plaid.Auth)

     ** (FunctionClauseError) no function clause matching in Forma.Typespecs.map/3

     The following arguments were given to Forma.Typespecs.map/3:
     
         # 1
         [{:type, 26, :map_field_assoc, [{:atom, 0, :options}, {:type, 26, :map, [{:type, 27, :map_field_assoc, [{:atom, 0, :account_ids}, {:type, 0, :list, [{:remote_type, 27, [{:atom, 0, String}, {:atom, 0, :t}, []]}]}]}]}]}]
     
         # 2
         Plaid.Auth
     
         # 3
         %{"access_token" => {:access_token, {{String, :t}, []}}}
     
     Attempted function clauses (showing 2 out of 2):
     
         def map([{:type, _, :map_field_exact, [{field_type, _, name}, typ]} | rest], module, acc)
         def map([], _module, acc)

Would be helpful to either allow a custom rewriters prop to be added to Form.Typespecs.compile/1 as in:

def compile(module, rewriters \\ %{}) do
    module
    |> Kernel.Typespec.beam_types()
    |> rewrite(module, rewriters)
    |> Enum.map(fn {t, d} -> {{module, t}, d} end)
    |> Enum.into(%{})
  end

  ...

  # Add rewriters arg on final pattern match
  def rewrite([], _, _module, rewriters) do
    ...
  end
end
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

1 participant