Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-boolean Missing found in boolean context (1/2 union split): goto %44 if not _4::Union{Missing, Bool} #457

Closed
lgeissbauer-btig opened this issue Jan 16, 2023 · 3 comments

Comments

@lgeissbauer-btig
Copy link

julia> function f()
           v = rand([["" => ""], nothing])
           println("$(v)")
       end
f (generic function with 1 method)

julia> JET.@report_call f()
═════ 2 possible errors found ═════
┌ @ REPL[22]:3 string(v)
│┌ @ strings/io.jl:185 Base.print_to_string(xs...)
││┌ @ strings/io.jl:144 print(s, x)
│││┌ @ strings/io.jl:35 show(io, x)
││││┌ @ arrayshow.jl:484 Base.show_vector(io, X)
│││││┌ @ arrayshow.jl:513 #self#(io, v, [, ])
││││││┌ @ arrayshow.jl:513 Base.typeinfo_prefix(io, v)
│││││││┌ @ arrayshow.jl:581 Base.typeinfo_implicit(eltype_X)
││││││││┌ @ arrayshow.jl:551 goto %44 if not _4
│││││││││ non-boolean `Missing` found in boolean context (1/2 union split): goto %44 if not _4::Union{Missing, Bool}
││││││││└────────────────────
│││││││┌ @ arrayshow.jl:581 goto %61 if not Base.typeinfo_implicit(eltype_X)
││││││││ non-boolean `Missing` found in boolean context (1/2 union split): goto %61 if not Base.typeinfo_implicit(eltype_X::Type{Pair{String, String}})::Union{Missing, Bool}
│││││││└────────────────────
@timholy
Copy link
Collaborator

timholy commented Jan 16, 2023

Are you claiming this is a JET bug? (Without having looked at the code, the report seems plausible to me.) If not, wouldn't Julia itself be a better place to report this?

@timholy
Copy link
Collaborator

timholy commented Jan 16, 2023

It might also be worth noting that not all JET reports require action. Take this one as an example: inference can't prove that some call doesn't return missing, and then gets used in a ::Bool-only context. But the "fix" would be to introduce an explicit error. The original code must look like this:

julia> x = missing
missing

julia> if x
           println("OK!")
       end
ERROR: TypeError: non-boolean (Missing) used in boolean context
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

and JET doesn't like the fact that x might be missing. The "fix" that would make JET happy is

julia> begin
           if !isa(x, Bool)
               error("x should be a Bool, got $x")
           end
           if x
               println("OK!")
           end
       end
ERROR: x should be a Bool, got missing
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ REPL[4]:3

But I think this is scarcely an improvement, so personally I would just ignore this report.

@timholy
Copy link
Collaborator

timholy commented Jan 19, 2023

Since I don't think there's any action needed, let's close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants