Skip to content

Weird type inference(?) behavior with a type unstable creation of a type wrapping a vector of tuples. #16530

@KristofferC

Description

@KristofferC

This is a reduced example of some code that started failing for me. I haven't bisected it but my guess is the Vararg changes but it could also be something with when typeof is evaluated, @timholy

type Foo{dim}
    c::Vector{NTuple{dim, Float64}}
end

function f()
    sdim = 1+1
    c = Vector{NTuple{sdim, Float64}}(1)
    c[1] = (1.0, 2.0)
    a = Foo{sdim}(c)
    println(typeof(a.c))
    return a
end

a = f()
println(typeof(a.c))

Executing this on current master gives:

julia> a = f();
Array{Tuple{Vararg},1}

julia> println(typeof(a.c))
Array{Tuple{Float64,Float64},1}

Inside the function, typeof(a.c) is Array{Tuple{Vararg},1} but outside it is Array{Tuple{Float64,Float64},1}. Note that this problem goes away if sdim is made a constant. This also seems to go away if instead of storing a Vector{NTuple} a simple NTuple is stored.

On an old 0.5 commit this gives the expected:

julia> a = f();
Array{Tuple{Float64,Float64},1}

julia> println(typeof(a.c))
Array{Tuple{Float64,Float64},1}

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorcompiler:inferenceType inferenceregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions