Skip to content

Display error if struct contains LabelledArray with mixed types #46

Closed

Description

@jishnub

Struct does not get displayed if it contains a labelled array with mixed types.

julia> using LabelledArrays

julia> T = @SLVector (:x,:y,:z)
SLArray{Tuple{3},1,(:x, :y, :z),T} where T

julia> T(1,2,3.4)
3-element SLArray{Tuple{3},1,(:x, :y, :z),Real}:
 1  
 2  
 3.4

julia> [typeof(x) for x in T(1,2,3.4)]
3-element StaticArrays.SizedArray{Tuple{3},DataType,1,1}:
 Int64  
 Int64  
 Float64

julia> struct H
       var :: T
       end

julia> a=H(T(1,2,3.4))
H(Error showing value of type H:
ERROR: MethodError: Cannot `convert` an object of type LabelledArrays.DisplayCell{Int64} to an object of type LabelledArrays.DisplayCell{Real}
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:154
  LabelledArrays.DisplayCell{Real}(::Any, ::Any) where T at /home/user/.julia/packages/LabelledArrays/Y2gSe/src/display.jl:2
Stacktrace:
 [1] setindex!(::Array{LabelledArrays.DisplayCell{Real},1}, ::LabelledArrays.DisplayCell{Int64}, ::Int64) at ./array.jl:767
 [2] show(::IOContext{REPL.Terminals.TTYTerminal}, ::SLArray{Tuple{3},1,(:x, :y, :z),Real}) at /home/user/.julia/packages/LabelledArrays/Y2gSe/src/display.jl:22
 [3] show_default(::IOContext{REPL.Terminals.TTYTerminal}, ::Any) at ./show.jl:332
 [4] show at ./show.jl:315 [inlined]
 [5] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::H) at ./sysimg.jl:194
 [6] display(::REPL.REPLDisplay, ::MIME{Symbol("text/plain")}, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:131
 [7] display(::REPL.REPLDisplay, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:135
 [8] display(::Any) at ./multimedia.jl:287
 [9] #invokelatest#1 at ./essentials.jl:742 [inlined]
 [10] invokelatest at ./essentials.jl:741 [inlined]
 [11] print_response(::IO, ::Any, ::Any, ::Bool, ::Bool, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:155
 [12] print_response(::REPL.AbstractREPL, ::Any, ::Any, ::Bool, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:140
 [13] (::getfield(REPL, Symbol("#do_respond#38")){Bool,getfield(REPL, Symbol("##48#57")){REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:714
 [14] #invokelatest#1 at ./essentials.jl:742 [inlined]
 [15] invokelatest at ./essentials.jl:741 [inlined]
 [16] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:2273
 [17] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:1035
 [18] run_repl(::REPL.AbstractREPL, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:192
 [19] (::getfield(Base, Symbol("##734#736")){Bool,Bool,Bool,Bool})(::Module) at ./client.jl:362
 [20] #invokelatest#1 at ./essentials.jl:742 [inlined]
 [21] invokelatest at ./essentials.jl:741 [inlined]
 [22] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:346
 [23] exec_options(::Base.JLOptions) at ./client.jl:284
 [24] _start() at ./client.jl:436

Activity

  1. ChrisRackauckas-Claude commented on Sep 23, 2026

    @ChrisRackauckas-Claude
    Member

    This no longer reproduces. A SLArray with mixed element types inside a struct now displays correctly.

    Tested on Julia 1.12.4 with LabelledArrays v1.20.5 (the latest release) and with LabelledArrays master (8369735):

    using LabelledArrays
    struct H
        var
    end
    S = SLArray{Tuple{3}, Real, 1, 3, (:x, :y, :z)}
    show(stdout, MIME"text/plain"(), H(S(LabelledArrays.StaticArrays.SVector{3, Real}(1, 2, 3.4))))
    H(3-element SLArray{Tuple{3}, Real, 1, 3, (:x, :y, :z)} with indices SOneTo(3):
     :x => 1
     :y => 2
     :z => 3.4)
    

    The display code that failed here was removed in #66. T(1,2,3.4) also no longer produces a Real eltype; it promotes to Float64.

    One separate thing turned up while testing. With T = @SLVector (:x,:y,:z), T(1,2,3.4) isa T is false: the macro builds SLArray{Tuple{3}, (:x,:y,:z)}, which puts the names in the element-type slot. The issue's struct H; var::T; end therefore now throws a TypeError at construction instead of failing in show. That is an API question about how the macro is parameterized, closer to #166 than to this issue. @SLVector Float64 (:x,:y,:z) does satisfy isa.

    Closing. Please reopen if the display problem still happens for you.


    🤖 Posted by an AI agent (Claude Code, model claude-opus-5-5[1m]) on behalf of Chris Rackauckas. Session: https://claude.ai/code/session_01NdFVhANTF4nepTbqYxjfRP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions