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

Indexing by non-empty mask #558

Open
orenbenkiki opened this issue Jul 27, 2023 · 0 comments
Open

Indexing by non-empty mask #558

orenbenkiki opened this issue Jul 27, 2023 · 0 comments

Comments

@orenbenkiki
Copy link

Synthetic example:

function mask(flag::Bool)::Vector{Bool}
    return Bool[flag, false]
end

function oops(flag::Bool)::Nothing
    values = Int[1, 2]
    used = mask(flag)
    if length(used) == length(values) && any(used)
        values[used]
    end
    return nothing
end

oops(true)
oops(false)

Will fail with an error pointing to the innards of Base.LogicalIndex. I'm not 100% sure whether the problem is that the system thinks used may be the wrong length, or that it may be all-false, or something else, but either way, it is a false positive.

I actually like it that JET emits an error here, forcing one to think about this (though the actual error is extremely opaque).

The problem is, there's currently no way to tell JET "kindly shut up about this, I know what I'm doing" (#515, #346, #148, ...).

Is there a workaround?

@orenbenkiki orenbenkiki changed the title Indexing by nnonn-empty mask Indexing by non-empty mask Jul 27, 2023
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

1 participant