Skip to content

incomplete inference with && and || branches #35090

@pdeffebach

Description

@pdeffebach

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:inferenceType inferencefeatureIndicates new feature / enhancement requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions