Skip to content

Handle custom typespec rewrites #4

@sitch

Description

@sitch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions