Skip to content

suboptimal abstract return type inference involving getindex(::Tuple) #55155

@nsajko

Description

@nsajko
julia> f(t::Tuple, n::Bool) = t[10 + n]
f (generic function with 1 method)

julia> Core.Compiler.return_type(f, Tuple{Tuple{Bool,String,Vararg{Int}},Bool})
Union{Bool, Int64, String}

julia> versioninfo()
Julia Version 1.12.0-DEV.unknown
Commit 0fdd655 (2024-07-17 15:39 UTC)

Ideally, the inferred return type would be Int. Proof: the index 10 + n is always either 10 or 11, thus the index is always greater than two.

Context, hypothesized solution approach using refinement types: https://discourse.julialang.org/t/would-it-make-sense-for-julia-to-adopt-refinement-types/113586/10

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setscompiler:inferenceType inferencefeatureIndicates new feature / enhancement requeststypes and dispatchTypes, subtyping and method dispatch

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions