# Computed supertypes

**URL:** <https://discourse.julialang.org/t/computed-supertypes/129913>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 16, 2025, 9:46am UTC](https://discourse.julialang.org/t/computed-supertypes/129913 "2025-06-16T09:46:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 16, 2025, 9:46am UTC](https://discourse.julialang.org/t/computed-supertypes/129913/1 "2025-06-16T09:46:28Z")

</div>

I am wondering if supertypes that are _computed_ are explicitly supported. Eg consider

```julia
using Enzyme
struct MockEnzymeMode <: supertype(typeof(Enzyme.Reverse)) end

```

where I construct an Enzyme.jl mode for testing an API (it should error as unimplemented), because the type params of `Enzyme.Mode` are not part of its API so I have to resort to these kind of tricks.

_Empirically_, these things work, eg

```julia
struct Foo <: supertype(typeof([1.0, 2.0, 3.0])) end

```

will be `<:Vector{Float64}`. But I am wondering if they are _explicitly_ supported. I could not find a mention in the manual. I am implicitly assuming that the value used is that obtained the time the expression was lowered, eg

```julia
gimmetype() = Vector{Float64}
struct Bar <: supertype(gimmetype()) end
gimmetype() = Vector{Int} # overwrite

```

will not change the type definition.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [June 16, 2025, 10:05am UTC](https://discourse.julialang.org/t/computed-supertypes/129913/2 "2025-06-16T10:05:48Z")

</div>

Hard to say about “explicitly supported”, but the documented semantics are that a struct definition is just an expression that is required to be top-level, and is computed in the order it appears in a file, and is definitely allowed to have computed parts to it.

So I’d say yes this is fine, and you appear to have the correct mental model for how it works.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 16, 2025, 12:08pm UTC](https://discourse.julialang.org/t/computed-supertypes/129913/3 "2025-06-16T12:08:21Z")

</div>

I realized that this is not very different from another common use case: computed types in _method signatures_. `::typeof(...)` is a common example, but in theory any function could be there.

I think it would make sense to write up a short note in some corner of the manual, about this application, good practices, caveats. I would make a PR but I am not sure where this belongs; I will wait for comments.
