JET.jl false positive "possible error" reported on Union{Bool, Nohing}
algunion opened this issue · comments
I think that JET
is not working properly for the following scenario:
@kwdef struct MyStruct
boolornothing::Union{Bool,Nothing} = nothing
end
function(mys::MyStruct)
if isnothing(mys.boolornothing) || !mys.boolornothing
return "nothing"
else
return "something"
end
end
I think it can be inferred that !mys.boolornothing
check will not happen when the boolornothing
is set to nothing
.
However, when using JET to check my code, it throws no matching method found !(::Nothing)
as a possible error. That error is not possible in the context.
I tried to help it by adding mys.boolornoting is a Bool && !mys.boolornothing
- but the same result - it is afraid that I am somehow calling !(::Nothing)
.
The reported issue is encountered when calling JET.test_package
function.
Is there a workaround until the inference quality improves? Or can I add something to my code to instruct JET
in ignoring certain functions?
Add something(). However, on julia 1.10, afaik something
should not be required any more in this case since the field is immutable.
@kwdef struct MyStruct
boolornothing::Union{Bool,Nothing} = nothing
end
function(mys::MyStruct)
if isnothing(mys.boolornothing) || !something(mys.boolornothing)
return "nothing"
else
return "something"
end
end
Thanks. It works.