# Aliased parameterized type confusion, cannot construct instance

**URL:** <https://discourse.julialang.org/t/aliased-parameterized-type-confusion-cannot-construct-instance/89088>\
**Category:** General Usage\
**Created:** [October 21, 2022, 10:19pm UTC](https://discourse.julialang.org/t/aliased-parameterized-type-confusion-cannot-construct-instance/89088 "2022-10-21T22:19:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 21, 2022, 10:19pm UTC](https://discourse.julialang.org/t/aliased-parameterized-type-confusion-cannot-construct-instance/89088/1 "2022-10-21T22:19:57Z")

</div>

Why does this work,

```julia
tst{T <: AbstractFloat} = SMatrix{3,3,T}

tst(rand(3,3))

3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.901624 0.966323 0.397229
 0.716175 0.758242 0.791737
 0.839526 0.798434 0.311178

```

but this does not?

```julia
tst2{T <: AbstractFloat} = UpperTriangular{T,SMatrix{3,3,T}}

tst2(rand(3,3))
MethodError: no method matching (UpperTriangular{T, SMatrix{3, 3, T}} where T<:AbstractFloat)(::Matrix{Float64})

Stacktrace:
 [1] top-level scope
   @ In[8]:1
 [2] eval
   @ ./boot.jl:368 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1428

```

Thanks!

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 22, 2022, 12:17am UTC](https://discourse.julialang.org/t/aliased-parameterized-type-confusion-cannot-construct-instance/89088/2 "2022-10-22T00:17:20Z")

</div>

nothing to do with alias:

```julia
julia> convert((SMatrix{3, 3, T} where T<:AbstractFloat), rand(3,3))
3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.60079 0.0957968 0.160429
 0.0510449 0.0892437 0.435343
 0.897627 0.389427 0.964163

julia> convert((UpperTriangular{T,SMatrix{3,3,T}} where T<:AbstractFloat), rand(3,3))
ERROR: MethodError: Cannot `convert` an object of type
  Matrix{Float64} to an object of type
  UpperTriangular{T, SMatrix{3, 3, T}} where T<:AbstractFloat

```

> <https://github.com/JuliaArrays/StaticArrays.jl/blob/a7ba6a2192351531a7535fa8b68aa389d54efaff/src/convert.jl#L171-L177>

there’s no equivalent for `UpperTriangular`

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 22, 2022, 9:25am UTC](https://discourse.julialang.org/t/aliased-parameterized-type-confusion-cannot-construct-instance/89088/3 "2022-10-22T09:25:37Z")

</div>

This case works because the eltype is known,

```julia
UpperTriangular{Float32,SMatrix{3,3,Float32}}(rand(3,3))

 3×3 UpperTriangular{Float32, SMatrix{3, 3, Float32}}:
 0.784383 0.599959 0.838959
  ⋅ 0.0565993 0.620415
  ⋅ ⋅ 0.118366

```

But I don’t see how it relates to your comment.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 22, 2022, 1:18pm UTC](https://discourse.julialang.org/t/aliased-parameterized-type-confusion-cannot-construct-instance/89088/4 "2022-10-22T13:18:15Z")

</div>

Because that’s a contractor and is defined here:

> <https://github.com/JuliaLang/julia/blob/v1.8.2/stdlib/LinearAlgebra/src/triangular.jl#L15-L19>

what I’m saying is simple, if there’s no definition for a `convert` then there’s no conversion that can take place.

When the outermost container is a StaticArray, that `convert` is implemented in `StaticArrays.jl` package.
