Skip to content

Support better representation of extension types in the debugger #53461

Open

Description

@annagrin

Parent: #49739

We don't currently show much useful information in the debugger for the extension types, as they don't exist at runtime.

Providing a useful experience would require bigger changes though the whole tooling ecosystem:

Design: describe how we present the static extension types to the user in the debugger UI
CFE (incremental compiler), frontend server, expression compiler worker: provide static types to the expression evaluation API.
vm service, vm, dwds: use the new API
DevTools: present static types and using new vm service API

Activity

  1. added
    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.
    on Sep 7, 2023
  2. added
    P2A bug or feature request we're likely to work on
    on Nov 3, 2023
  3. loic-sharma commented on Oct 9, 2026

    @loic-sharma
    Contributor

    The Flutter team is working on guidance for "open enums": flutter/rfc#32

    Unfortunately, extension types impact debuggability:

    void main(List<String> arguments) {
      var e1 = E1.foo; // e1 = E1 (E1.foo)
      var e2 = E2.foo; // e2 = 1
    }
    
    enum E1 { foo, bar }
    
    extension type const E2._(int index) {
      static const E2 foo = E2._(0);
      static const E2 bar = E2._(1);
    
      // Extension types can't declare members with the same name as a member declared by 'Object'.
      // Try specifying a different name for the member.
      // dart(extension_type_declares_member_of_object)
      // @override
      // String toString() => 'E2.$value';
    }

    Perhaps Dart could do something like C#'s DebuggerDisplayAttribute - an attribute which lets you specify how debuggers should display a value, which has higher precedence than toString()?

    Example strawman:

    void main(List<String> arguments) {
      var e1 = E1.foo; // e1 = E1 (E1.foo)
      var e2 = E2.foo; // e2 = E2.foo
    }
    
    enum E1 { foo, bar }
    
    @debuggerDisplay('{_debuggerDisplay}')
    extension type const E2._(int index) {
      static const E2 foo = E2._(0);
      static const E2 bar = E2._(1);
    
      String _debuggerDisplay() {
        const names = ['foo', 'bar'];
        return 'E2.${names[index]}';
      }
    }
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

    P2A bug or feature request we're likely to work onarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-dev-compilerweb-evalevaluation support on the web

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions