Skip to content

Debugger displays custom type variants starting with non-ASCII as <internals> #141

@lydell

Description

@lydell

SSCCE:

module Main exposing (main)

import Browser
import Html
import Html.Events


type Msg
    = Pärtan SubMsg


type SubMsg
    = Ärtan


main =
    Browser.sandbox
        { init =
            { startsWithAscii = Pärtan Ärtan
            , startsWithUnicode = Ärtan
            }
        , update = always identity
        , view =
            \_ ->
                Html.button [ Html.Events.onClick (Pärtan Ärtan) ]
                    [ Html.text "Click me, then open the debugger" ]
        }
Image

Notice how:

  • The messages history on the left correctly displays Pärtan Ärtan.
  • The current message on the right instead displays Pärtan <internals>.
  • The model on the right displays Pärtan <internals> and <internals>.

The reason it works in the messages history but not in the main view is because there are two functions that displays Elm values – and only one of them is correct.

  1. _Debugger_messageToString is used for the messages history. In short, it considers custom types with an ASCII lowercase first letter as internal (such as a3, which is a virtual DOM attribute), and all other custom types as displayable. https://github.com/elm/browser/blob/1.0.2/src/Elm/Kernel/Debugger.js#L356-L376

  2. _Debugger_init is used for the main view (both for the message and the model). In short, it kind of does the opposite: It considers a custom type with an ASCII uppercase first letter as displayable, and all other custom types as internal. That is equivalent to the approach in _Debugger_messageToStringbut only for ASCII. Elm supports custom type variants that starts with any unicode uppercase letter. https://github.com/elm/browser/blob/1.0.2/src/Elm/Kernel/Debugger.js#L439-L451

The solution is to use the _Debugger_messageToString approach in _Debugger_init too: Hide ASCII lowercase, and display others.

Expected:

Image

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