Skip to content

Inconsistencies with multi-argument constructors #518

Open
@timholy

Description

@timholy

Given that Scalar <: SArray, the behavior of

@inline Scalar(a::AbstractArray) = Scalar{typeof(a)}((a,))

is inconsistent with
@inline (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a)

Fortunately, in a few cases there's a very welcome ambiguity error:

julia> sa = Scalar((1,))
Scalar{Int64}((1,))

julia> Scalar(sa)
ERROR: MethodError: Scalar{T} where T(::Scalar{T}) is ambiguous. Candidates:
  (::Type{Scalar{T} where T})(a::AbstractArray{T,0} where T) in StaticArrays at /home/tim/.julia/dev/StaticArrays/src/Scalar.jl:11
  (::Type{Scalar{T} where T})(a::AbstractArray) in StaticArrays at /home/tim/.julia/dev/StaticArrays/src/Scalar.jl:10
  (::Type{SA})(a::StaticArray) where SA<:StaticArray in StaticArrays at /home/tim/.julia/dev/StaticArrays/src/convert.jl:4
Possible fix, define
  Scalar{T} where T(::StaticArray{S,T,0} where T where S<:Tuple)
Stacktrace:
 [1] top-level scope at none:0

but mostly this just silently does things differently for 0 dimensions than for any other dimension.

I don't think you can really have both. Can you choose which behavior you want to keep?

Metadata

Metadata

Assignees

No one assigned

    Labels

    designspeculative design related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions