Skip to content

Error message does not indicate conflicting type parameters #42401

Closed
@tyleringebrand

Description

@tyleringebrand

Originally found here, the issue is a error message for incorrect code is very misleading. Here is a minimum working example:

struct X{T, A<:AbstractArray{T}}
    t::T
    a::A
end

Vector{X{Int, Vector{Float64}}}(undef, 2)

The issue is that Float64 does not match Int, which causes an error. However, the error message is:

ERROR: LoadError: TypeError: in X, in A, expected A<:(AbstractArray{T, N} where N), got Type{Vector{Float64}}
Stacktrace:
 [1] top-level scope
   @ c:\Users\Tyler\Documents\Julia\Learning\test.jl:6
in expression starting at c:\Users\Tyler\Documents\Julia\Learning\test.jl:6

The reason why this is confusing is because it says the issue is with A being of type AbstractArray{T, N} and that the actual type is Vector{Float64}. Vector is of type AbstractArray, and Float64 is a type. Therefore, I could not figure out why this is wrong because it does seem like the type of A given, Vector{Float64}, is a valid type of A, AbstractArray{T}.
It would be nice if the error message specified that the given Types were wrong because Float64 does not match Int and therefore T is being redefined.

Note in this example it may seem obvious, but this can become quite confusing for a more complicated struct.

If version is relevant:

Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)      
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messagesBetter, more actionable error messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions