maxguzenski
Nil > 25 returns true – is this expected behavior?
Hi everyone,
I’m using Elixir 1.18.4 with OTP 27 (I’ve tested this across multiple versions of both Elixir and Erlang), and surprisingly, the expression nil > 25 returns true. Is this correct?
Both ChatGPT and Claude stated that this should not be possible — that a comparison like this should raise an ArgumentError, as nil cannot be compared to numbers using > or <. They even suggested that something might be wrong with my machine.
However, I tested this on https://playground.functional-rewire.com/ as well, and I got the same result: nil > 25 returns true.
So my question is:
Has it always been this way, or is this a recent change/bug?
Thanks in advance!
Most Liked
sabiwara
While there is no runtime warning for the reasons explained above, it’s worth noting that the new type system might be able to catch it and warn at compile time when it is sure types are disjoint:
comparison between distinct types found:
nil > 25
given types:
nil > integer()
While Elixir can compare across all types, you are comparing across types which are always disjoint, and the result is either always true or always false
sodapopcan
You sound like one of those people who actually know how to use a dynamic programming language properly
Also, we’re in the BEAM world here so I believe you meant “behaviour” ![]()
As grumpy old man jumping on the opportunity to rant this has been fairly common recently, “common” meaning this is the ~7th time in a couple of months I’ve seen a question online where people said they just asked AI, and not just for Elixir questions! I’m sure it’ll all be “fixed” soon enough, but I still enjoy reading docs.
Back on track, another little gotcha is that true and false are also sugar for :true and :false, so when you throw nil into the mix and compare them it’s done so alphabetically. I know a couple of people who got tripped up by this because they assumed that since true is greater than false that false would be greater than nil, but it’s not. Though again, if you aren’t abusing dynamic languages then you’ll never run into this ![]()
k, I’m off to go yell at a cloud.
adamu
software developers in particular are prone to being convinced by these hazards and few in the field seem to have ever had that “oh my, I can’t always trust my own judgement and reasoning” moment
Popular in Questions
Other popular topics
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
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








