# Interesting behaviour with parametric types in inner constructors

**URL:** <https://discourse.julialang.org/t/interesting-behaviour-with-parametric-types-in-inner-constructors/131290>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 1, 2025, 1:51pm UTC](https://discourse.julialang.org/t/interesting-behaviour-with-parametric-types-in-inner-constructors/131290 "2025-08-01T13:51:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas-pueschel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonas-pueschel/32/213890_2.png) [@jonas-pueschel](https://discourse.julialang.org/u/jonas-pueschel)\
**Post date:** [August 1, 2025, 1:51pm UTC](https://discourse.julialang.org/t/interesting-behaviour-with-parametric-types-in-inner-constructors/131290/1 "2025-08-01T13:51:52Z")

</div>

Hi all,  
I recently stumbled over an interesting behaviour regarding parametric types used in inner constructors. The short version is, that this code

```julia
struct TestStruct1{Tx<:Integer,Ty<:Float64}
    x::Tx
    y::Ty
    function TestStruct1{Ty}(y::Ty) where {Ty<:Float64}
        x = 0
        return new{typeof(x),Ty}(x,y)
    end
end
TestStruct1{Float64}(0.0)

```

throws an error without even calling the constructor, namely

```julia-auto
ERROR: TypeError: in TestStruct1, in Tx, expected Tx<:Integer, got Type{Float64}

```

The line given in the error text is the call of `TestStruct1` at the bottom.

However this code

```julia
struct TestStruct2{Ty<:Float64,Tx<:Integer}
    x::Tx
    y::Ty
    function TestStruct2{Ty}(y::Ty) where {Ty<:Float64}
        x = 0
        return new{Ty,typeof(x)}(x,y)
    end
end
TestStruct2{Float64}(0.0)

```

where only `Ty` and `Tx` are switched in the curly braces, works fine. After some trial and error I found out, that for `struct TestStruct{T1,...,Tn}` only inner constructors of the form `function TestStruct{T1,...,Tk}` will be run correctly, anything out of order or skipping a `Ti` will break the code.  
Is this behaviour intended?

---

<div class="post-metadata">

**Author:** ![aryavorskiy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aryavorskiy/32/43466_2.png) [@aryavorskiy](https://discourse.julialang.org/u/aryavorskiy)\
**Post date:** [August 1, 2025, 2:02pm UTC](https://discourse.julialang.org/t/interesting-behaviour-with-parametric-types-in-inner-constructors/131290/2 "2025-08-01T14:02:00Z")

</div>

Hi!

Type parameters in a struct are _not named_. Thus, `TestStruct1{Ty}` in both cases implies `Ty` as the first type parameter. Since in the first case you explicitly limited it to `<:Integer`, you get an error — Julia doesn’t allow you to define a constructor with a signature like this. This behavior is intended, because it’s not entirely clear what to do with the type parameters you skipped, and this implicit behavior is potentially error-prone.

Sidenote: You probably want `Ty<:Real` instead, because `Float64` is a concrete type.
