Skip to content

Commit

Permalink
Improve doc example: Extracting the type parameter from a super-type (#…
Browse files Browse the repository at this point in the history
…55983)

Documentation describes the correct way of extracting the element type
of a supertype:

https://docs.julialang.org/en/v1/manual/methods/#Extracting-the-type-parameter-from-a-super-type

However, one of the examples to showcase this is nonsensical since it is
a union of multiple element types.
I have replaced this example with a union over the dimension.
Now, the `eltype_wrong` function still gives a similar error, yet the
correct way returns the unambiguous answer.

---------

Co-authored-by: Lilith Orion Hafner <[email protected]>
  • Loading branch information
ArnoStrouwen and LilithHafner authored Oct 23, 2024
1 parent 0b9fcb5 commit 6c70bf7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions doc/src/manual/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,14 @@ While this works for declared types, it fails for types without
supertypes:

```julia-repl
julia> eltype_wrong(Union{AbstractArray{Int}, AbstractArray{Float64}})
ERROR: MethodError: no method matching supertype(::Type{Union{AbstractArray{Float64,N} where N, AbstractArray{Int64,N} where N}})
julia> eltype_wrong(Union{Vector{Int}, Matrix{Int}})
ERROR: MethodError: no method matching supertype(::Type{VecOrMat{Int64}})
Closest candidates are:
supertype(::DataType) at operators.jl:43
supertype(::UnionAll) at operators.jl:48
supertype(::UnionAll)
@ Base operators.jl:44
supertype(::DataType)
@ Base operators.jl:43
```

### Building a similar type with a different type parameter
Expand Down

0 comments on commit 6c70bf7

Please sign in to comment.