You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Correctness / Credo: In algae, use the map hack to present a macro st or "structual type", which will take a module and ask for a map with __struct__ field set to an appropriate value
#10
Open
4 tasks
cognivore opened this issue
Feb 24, 2023
· 1 comment
We sometimes need to go a bit deeper than 1-deep types when it comes to witchcraft.
But since defdata is evaluated during the final compilation pass (macro expansion step), defdata can't see itself (is non-recursive), nor can it see its neighbours.
However, for every type, we can actually "guess" how progressive typing of it will look at runtime. Elixir mimics "structures" with maps with a field __struct__ set to __MODULE__ where they were declared. For example:
iex(1)> defmodule D, do: defstruct [A, :b]
iex(4)> x = D.__struct__
%D{"Elixir.A": nil, b: nil}
iex(5)> x.__struct__
D
Sadly we can't use a macro here (duh), but we can nonetheless use %Mod{} syntax in typespecs, and disable credo alarm for the %Mod{} usage in typespecs.
Of typing a defdata: @type st :: %{required(:__struct__) => OnTheMap.Auth.Identity, optional(any()) => any()}.
Use this approach to add st type in defmodule implementation of goo! It won't know about the structure's fields, but it will at least be able to check for presence of the correct __struct__.
What do you think needs to be figured out for it to be done?
No response
The text was updated successfully, but these errors were encountered:
Since we've done big changes to code generation by making a new-less version of defdata and defsum in Algae Goo recently, we can tack this onto it first.
Why does it have to be done?
We sometimes need to go a bit deeper than 1-deep types when it comes to witchcraft.
But since
defdata
is evaluated during the final compilation pass (macro expansion step),defdata
can't see itself (is non-recursive), nor can it see its neighbours.However, for every type, we can actually "guess" how progressive typing of it will look at runtime. Elixir mimics "structures" with maps with a field
__struct__
set to__MODULE__
where they were declared. For example:Sadly we can't use a macro here (duh), but we can nonetheless use
%Mod{}
syntax in typespecs, and disable credo alarm for the%Mod{}
usage in typespecs.How do you think does it have to be done?
@type st :: %{required(:__struct__) => OnTheMap.Auth.Identity, optional(any()) => any()}
.st
type indefmodule
implementation ofgoo
! It won't know about the structure's fields, but it will at least be able to check for presence of the correct__struct__
.What do you think needs to be figured out for it to be done?
No response
The text was updated successfully, but these errors were encountered: