You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive for local variable in multiple if statements with the same condition #801
JET v0.11 seems to generate false positive warnings for the following setup, where multiple branches with a shared condition are used:
using JET
module MWE
functionf(m, n)
condition = m < n
if condition
some_variable =3end
mn = m + n
if condition
mn += some_variable
endreturn mn
endendusing.MWE
@report_call target_modules = (MWE,) MWE.f(1, 2)
While I agree that this might be a hard issue to solve in general, would there be a way to rewrite this such that JET can recognize that this is never an issue, or is there a fix for JET that can detect this?
I'm struggling to come up with a code pattern that can avoid this in a satisfactory manner.
The simplest approach seems to be to just define some_variable = nothing in the else branches, ensuring that the variable is always defined.
However, I don't think this guarantees that the compiler is always able to optimize away the resulting (union-split) type instability, and while in this specific case it is easy to create a dummy variable of the same type, this is not always easy or cheap (e.g. might require allocations).
This is a duplicate of #795 but with a simpler MWE, I wasn't sure if this needs its own issue or should be attached there.
Reacted by Kristian Holme, Tomáš Drvoštěp, Kiran Pamnany and Mosè Giordano
Activity
Avoid conditionally defined local variables (#2443)