Skip to content

Relax the constraint of parameter order for parameter type constructor #44861

@frankwswang

Description

@frankwswang
julia> struct myT{A<:Real, B}
           a::A
           myT{B}(a::A) where {A, B} = new{A, B}(a)
       end

julia> myT{Vector{Int}}(1, [1])
ERROR: TypeError: in myT, in A, expected A<:Real, got Type{Vector{Int64}}
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

Currently, when a constructor of a parameter type has explicit parameters in the {} part of its definition, even if not all of the parameters are included, they are still constrained by the type's struct definition. I wonder if this constraint could be loosened in the future release. This will make cases like the above prompt error exception. The reason I would need such a use case is to use the parameters in {} for multiple dispatch. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions