-
Notifications
You must be signed in to change notification settings - Fork 13
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
Gradient does not recognize type of TypedStruct structures #165
Comments
Hi, @Fl4m3Ph03n1x! Thanks for raising this. Could you also share the definition of Are you running the analysis on source files or beam files? However, the undefined function |
Sure !
I am running |
Is there something else I can do to help? |
I've looked at it a bit more, but it's not clear to me yet where the error comes from. It's certain the type is defined and the error message doesn't say that it's missing either. However, I'm not sure why the specific struct type A workaround would be to use a type assertion: use Gradient.TypeAnnotation
s = Structs.string_map_to_struct(auth, __MODULE__)
annotate_type(s, any())
|
If it is of any help, this module has the same issue, Version using defmodule Shared.Data.User do
@moduledoc """
Represents relevant User information for clients using this AuctionHouse.
"""
use TypedStruct
alias Shared.Utils.Structs
@type user ::
%{
(ingame_name :: String.t()) => String.t(),
(patreon? :: String.t()) => boolean()
}
| [ingame_name: String.t(), patreon?: boolean()]
@derive Jason.Encoder
typedstruct enforce: true do
@typedoc "User information"
field(:ingame_name, String.t())
field(:patreon?, boolean())
end
@spec new(user()) :: __MODULE__.t()
def new(%{"ingame_name" => name, "patreon?" => patreon?} = user)
when is_binary(name) and is_boolean(patreon?) do
Structs.string_map_to_struct(user, __MODULE__)
end
def new([ingame_name: name, patreon?: patreon?] = user)
when is_binary(name) and is_boolean(patreon?),
do: struct(__MODULE__, user)
end Returns with error:
While the version using native code: defmodule Shared.Data.User do
@moduledoc """
Represents relevant User information for clients using this AuctionHouse.
"""
alias Shared.Utils.Structs
@enforce_keys [:ingame_name, :patreon?]
defstruct [:ingame_name, :patreon?]
@type user ::
%{
(ingame_name :: String.t()) => String.t(),
(patreon? :: String.t()) => boolean()
}
| [ingame_name: String.t(), patreon?: boolean()]
@typedoc "User information"
@type t() :: %__MODULE__{
ingame_name: String.t(),
patreon?: boolean()
}
@spec new(user()) :: t()
def new(%{"ingame_name" => name, "patreon?" => patreon?} = user)
when is_binary(name) and is_boolean(patreon?),
do: Structs.string_map_to_struct(user, __MODULE__)
def new([ingame_name: name, patreon?: patreon?] = user)
when is_binary(name) and is_boolean(patreon?),
do: struct(__MODULE__, user)
end Errors with:
Interestingly enough, this will still happen if I inline the code: @spec new(user()) :: __MODULE__.t()
def new(%{"ingame_name" => name, "patreon?" => patreon?} = user)
when is_binary(name) and is_boolean(patreon?) do
atom_map = Morphix.atomorphiform!(user)
struct(__MODULE__, atom_map)
end Will complain with:
So at this point, I really do think there is a problem with |
I have a module that uses
TypedStruct
to create structs. This is the code:The problem here is that gradient does not seem to understand that
t()
is created, so it errors out:For additional context, here is the
string_map_to_struct
code:I decided to convert that code into its native form using
defstruct
:Gradient does not complain here.
Is there a fix for this?
(other than removing typed struct?)
The text was updated successfully, but these errors were encountered: