bartblast
Creator of Hologram
Typing violation warning when comparing atoms
Why comparing atoms gives typing violation warning?
consider:
defmodule MyModule do
def test do
:a < :b
end
end
mix compile my_module.ex
gives a warning:
Compiling 1 file (.ex)
warning: comparison between incompatible types found:
:a < :b
While Elixir can compare across all types, you are comparing across types which are always distinct, and the result is either always true or always false
typing violation found at:
│
3 │ :a < :b
│ ~
│
└─ my_module.ex:3:8: MyModule.test/0
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 10 of 13 Posts!
tcoopman
What’s the result you expected? What are you trying to do?
antoine-duchenet
Because
:aand:bare not considered to be of typeatom()but respectively as type:aand:b.LostKobrakai
And as mentioned in the warning the result of the comparison is static as well.
bartblast
Since the
<operator is inlined with:erlang.</2, I expected the compiler to resolve its typing to a parametric polymorphic definition, something akin to(a, a) -> boolean() when a: term(). I didn’t expect singleton types.I gave a simplified example to illustrate the problem, which I encountered when implementing client-server consistency tests in Hologram. Basically, I test whether manually transpiled Erlang functions behave exactly the same as their server counterparts.
LostKobrakai
If the typesystem has distinct types, why would it fall back to less specific types? This would be different if you would have variables here, but you hardcoded values for the comparison.
bartblast
@antoine-duchenet @LostKobrakai Guys, considering your previous answers, does this mean that Erlang functions are not treated as “atomic” functions for the type system and they don’t have hardcoded typings? Or maybe the underlying Erlang functions’ abstract code (or bytecode) is analysed as well in the process to determine the typings?
LostKobrakai
Not sure I get what you’re asking for, but I don’t think there’s much to it.
With 1.17 warnings where implemented to warn when comparisons are made between different types of data – mostly to warn for the common footgun of comparing structs like
DateTime, which would use structural comparison not semantic one. That’s the source of the warning.The reason for getting the warning if both sides are atoms comes from the fact that the new typesystem implementation considers atom() a divisable type, which includes all possible individual atoms. So
:aand:bare distinct types based on the typesystem, but both are part ofatom(). The wording sounds a bit unfortunate here though given it’s a bit ambiguous what type of “type” the error refers to.dimitarvp
He’s probably asking about BIFs and such.
LostKobrakai
BIFs are a runtime/implementation concern though. The compiler (and the typesystem) generally don’t care about any of that.
dimitarvp
So your functions that call them would never be type-checked by Dialyzer whether they pass the right types of arguments to BIFs, is that what you’re saying?
Last Post!
sabiwara
I’m not sure if I understand your question correctly, but functions applications (
Foo.bar(baz)or:foo.bar(baz)) are not typed yet, this will come with future releases.Standard library functions from Elixir and Erlang will be typed then.