julia> f() = missing <= 2 <= 3 f (generic function with 1 method) julia> @code_lowered f() CodeInfo( 1 ─ %1 = Main.missing <= 2 └── goto #3 if not %1 2 ─ %3 = 2 <= 3 └── return %3 3 ─ return false ) julia> f() ERROR: TypeError: non-boolean (Missing) used in boolean contextStacktrace:  f() @ Main .\REPL:1  top-level scope @ REPL:1
Chained comparisons “use the
&& operator for scalar comparisons”. This means that your code is equivalent to something like:
missing <= 2 && 2 <= 3
which fails because the
&& short-circuit operator cannot handle
Just explicitly write it out and use
(missing <= 2) & (2 <= 3). Note that parentheses are needed because
& has higher precedence than
Of course… I’ve seen it, too much syntax lets me forget meaning.
I see why it doesn’t work and how to prevent it. But shouldn’t we fix it? Seems inconsistent
It seems like fixing it would require changing chained comparisons to use
& instead of
&&. This has been discussed previously in
and the conclusion by @jeff.bezanson in the latter issue was:
Unfortunately I don’t see a non-breaking way to implement this.
which means it will have to wait until 2.0 (if ever)?
Can you file an issue at MissingsAsFalse.jl? Currently the
@mfalse macro does not support this chained comparison, but it would be a good addition.