Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #147
Each commit here fixes one set of problems.
The main problem was Ecto 2.1 defining a bunch of opaque types and then peeking inside of them with macros. In Ecto 2.2, the types are not marked as opaque and so you don't get clobbered by giant warning messages that you're not even responsible for. This is complicated by ecto_enum insisting on Ecto 2.1 even though it doesn't seem to actually need it. I overrode ecto_enum, pending gjaldon/ecto_enum#45 getting merged, but you may prefer to avoid this and just deal with Ecto 2.1.
I think most of the dialyzer errors after that fix are pretty readable. I'll go over my other fixes in detail.
First, Dialyzer errors tend to cascade: one little error deep in the call stack will cause problems all the way up the stack. Therefore, you should generally try to work on the deepest error first and if the error you're looking at doesn't make sense, just fix some other errors and re-run to see if things become clearer.
One error we see is
This basically means "according to type analysis, this function will always crash". Which really means that there's some type problem below and so we should keep looking.
Another error is
Dialyzer is Erlang, so module names and functions look slightly different, but we can just squint. This says that you're calling
OpenPantry.UserOrder.all(:user)
but theall/1
function expects a list of atoms, not a single atom.Looking at the code, it seems like the typespec got typo'd.
list(atom() | atom())
which it's meant to belist(atom()) | atom()
.A large, scary one is
(sorry that's unreadable in Github...)
Anyway, it's mostly just printing the
Plug.Conn
struct, so you have to skim over that. The best bet is at the end:If you look it up, this is
Phoenix.Controller.render/3
that Dialyzer is talking about, but we're passing a view so this should bePhoenix.Controller.render/4
!And finally:
Again, the struct expansion makes this look harder than it is. I use iTerm2 which lets me double-click to select matching delimeters, and I use that to help visualize the error.
The error says that the success type (what Dialyzer sees will actually happen) is
This is obvious from the function, so the given typespec was just wrong. I corrected it by defining a new type
stockable()
. Defining a new type to express what's going on is almost always a good idea, since it's another form of documentation.The only remaining Dialyzer errors I see is for
OpenPantry.FoodSelection.Stock
. It's similar to the above, but I wasn't sure what was going on becauseMeal
andOffer
are the same as above butFood
is a different module.I hope this was helpful! Dialyzer can be frustrating to learn but it's caught some tricky errors for me in the past! (I think the
render/3
/render/4
error is probably a good example)