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

incomplete inference with && and || branches #35090

Open
pdeffebach opened this issue Mar 12, 2020 · 0 comments
Open

incomplete inference with && and || branches #35090

pdeffebach opened this issue Mar 12, 2020 · 0 comments
Labels
compiler:inference Type inference feature Indicates new feature / enhancement requests

Comments

@pdeffebach
Copy link
Contributor

I have attached an MWE gist with an error for type inference discussed here on Discourse. It is relevant because I ran into this while working on this PR in Missings.jl

The MWE (though "minimum" is a stretch) defines a struct and then 3 mapreduce_impl functions. Two good, one bad.

The struct, TwoVectors, is two vectors x and y which both contain missing values. The goal is to mapreduce_impl across the x field while omitting elements where either x or y are missing.

All three mapreduce_impl functions have the same behavior, but the "bad" one doesn't infer correctly. They are all the exact same except for a section starting on the 4th line of each expression.

The "bad" one has this:

        if a1 !== missing && !_anymissingindex(itr.others, ifirst) 
        	return Some(Base.mapreduce_first(f, op, a1))
        end
       return nothing

The "good" one has this

        if a1 === missing 
        	return nothing
        elseif _anymissingindex(itr.others, ifirst)
        	return nothing
    	end 
    	return Some(Base.mapreduce_first(f, op, a1))

The "good2" one has this

        a1 === missing || _anymissingindex(itr.others, ifirst) || return Some(Base.mapreduce_first(f, op, a1))
        return nothing

The full @code_warntype output can be seen by calling MWEMissings.main().

@vtjnash vtjnash added feature Indicates new feature / enhancement requests compiler:inference Type inference labels Mar 13, 2020
@vtjnash vtjnash changed the title Bug with branching and code inference incomplete inference with && and || branches Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

2 participants