# Warntype\_last() outputs red ::Ref{Float64}

**URL:** <https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900>\
**Category:** General Usage\
**Created:** [February 20, 2023, 6:43am UTC](https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900 "2023-02-20T06:43:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [February 20, 2023, 6:43am UTC](https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900/1 "2023-02-20T06:43:50Z")

</div>

Unfortunately, I have not managed to create an MVE, but I think I can ask a good question:

I use a `Ref` to make a `Float64` mutable within a `struct`. Using a `mutable struct` arguably makes more sense, and resolves my issue, I checked, but I want to learn. This part of a larger code

```julia
struct OUTstaticX{Tλ,Tλx} 
    Lλ :: Tλ
    Lλx :: Tλx 
    α :: Ref{Float64}
end   
...
out.α[] = min(out.α[],α)

```

run with `Profile` and examined with `warntype_last()` outputs

```julia
│ %26 = Base.getproperty(out, :α)::Ref{Float64} # the type is typeset in red!!!
│ %27 = Base.getindex(%26)::Any

```

where `::Ref{Float64}` is typeset in red. This puzzles my neuron:

1. I assume that `warntype_last()` wraps `@code_warntype`, and that the later uses red to emphasize variables resolved to an `abstract` type by the compiler. Yet `Ref{Float64}` is a concrete type. **Under what conditions can my assumption be wrong?**
2. **How can a `Ref{Float64}` dereference to `Any`?**  
…and I am sure both surprises are related.

---

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [February 20, 2023, 7:53am UTC](https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900/2 "2023-02-20T07:53:39Z")

</div>

The surprise is here:

```julia
julia> isconcretetype(Ref{Float64})
false

```

And indeed

```julia
julia> subtypes(Ref)
6-element Vector{Any}:
 Base.CFunction
 Base.RefArray
 Base.RefValue
 Core.Compiler.RefValue
 Core.LLVMPtr
 Ptr

```

You were probably meant to annotate the field as `Base.RefValue` instead of `Ref`:

```julia
julia> typeof(Ref(1))
Base.RefValue{Int64}

```

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [February 20, 2023, 8:09am UTC](https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900/3 "2023-02-20T08:09:30Z")

</div>

Spot on!

I actually had to type `isconcretetype(Ref{Float64})` to check what you said 😆. I dare say the manual should be specific on which types that it describes are abstract or concrete.

Annoting the field in my struct as `Base.RefValue{Int64}` indeed makes the code typestable. 🕶 ☀

Hjertelig tusen takk!

Philippe

---

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [February 20, 2023, 8:11am UTC](https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900/4 "2023-02-20T08:11:03Z")

</div>

You may also consider making your struct mutable, and then annotate the non-changing fields `const`. I’d argue it’s more idiomatic, although that may incur a performance pentalty in some situations.

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [February 20, 2023, 8:13am UTC](https://discourse.julialang.org/t/warntype-last-outputs-red-ref-float64/94900/5 "2023-02-20T08:13:48Z")

</div>

That’s how I actually fixed my code… But it was worth asking: understanding that `Ref{X}` is always abstract is important.
