vans163
I am wondering if this is correct, this should be a map of arbitrary size (could be 0, could be 1000) of integer keys.
@type quests() :: %{Integer => any()}
defmodule GameState do
@type obj() :: %{0=> Integer, optional(1)=> Integer, optional(2)=> Integer}
@type quest() :: %{id: Integer, step: Integer, obj: obj()}
@type quests() :: %{Integer => quest()}
@type gamestate() :: %{quests: quests()}
@spec get_quests(gamestate()) :: quests()
def get_quests(gs) do
:erlang.map_get(:quests, gs)
end
@spec act(gamestate()) :: any()
def act(gamestate) do
quests = get_quests(gamestate)
cur_quest_id = quests
|> Map.keys()
|> List.last()
cur_quest = Map.fetch!(quests, cur_quest_id)
cur_objs = Table.QuestStep.by_id_order(cur_quest.id, cur_quest.step)
done_objs = Enum.filter(cur_objs, fn{idx,obj}->
cur_quest.obj[idx].amount >= obj.amount
end)
end
def go do
quest = %{id: 10010, step: 2, obj: %{0=> 14}}
quests = %{10010=> quest}
gamestate = %{quests: quests}
act(gamestate)
end
end
The idea here is to trigger a error from dialyzer here cur_quest.obj[idx].amount that .amount is not a valid key for obj().
Instead I get this, but if I call this from the REPL it works just fine. The function call succeeds.
lib/game/gamestate.ex:28:call
The function call will not succeed.
Table.QuestStep.by_id_order(Integer, Integer)
will never return since it differs in arguments with
positions 1st and 2nd from the success typing arguments:
(pos_integer(), 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)
Can anyone advise please?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
Integermean that you are matching against:"Elixir.Integer"atom, you wanted to useinteger()type.ityonemo
you probably want:
or maybe
I prefer omitting parens on non parametric types, to cut down on line noise, but if you prefer keeping them in (which I believe is idiomatic?):
asummers
Yikes I need to fix that message.
vans163
Awesome, it doesn’t have any errors now, which is troubling, it should error here
cur_quest.obj[idx].amountthat amount is not a field.It seems the Access module messes up so many things, if I replace the Access with a Map.fetch!() dialyzer picks it up and errors that
amountis invalid and can never match the type. Guessing maybe because the implied nil?Any ideas how to not lose the flexibly of the access module but keep dialyzer happy?
asummers
@vans163 mind checking out the
better-error-messagebranch on Dialyxir and seeing if that reads any better?vans163
Heh dialzyer with typespecs is not what we were looking for. So not sure if I will continue looking into this.
Basically because of that lol.
Waiting now to see if Facebook reveals anything interesting on Nov, if they made a totally new static typed language that compiles to beam that seems useless. If they build a new analysis tool or IL to spot type errors in beam files/core erlang that is more interesting now.
If nothing interesting from FB will probably take an attempt at walking compiled beam bytecode.