Skip to content

CFE ignores custom toString() method in enums #48084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexmarkov opened this issue Jan 5, 2022 · 0 comments
Closed

CFE ignores custom toString() method in enums #48084

alexmarkov opened this issue Jan 5, 2022 · 0 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@alexmarkov
Copy link
Contributor

This is a part of #47453.

Test co19/src/LanguageFeatures/Enhanced-Enum/semantics_A04_t02 currently fails with RuntimeError on the VM because custom implementation of toString() method in the enum class is ignored and replaced with synthetic in the front-end.

tests/co19/src/LanguageFeatures/Enhanced-Enum/semantics_A04_t02.dart:

enum E1 {
  e1,
  e2,
  e3;

  String toString() => "Enum E1.${this.name}";
}

Kernel:

  class E1 extends core::_Enum /*isEnum*/  {
    static const field core::List<sem::E1> values = #C10;
    static const field sem::E1 e1 = #C3;
    static const field sem::E1 e2 = #C6;
    static const field sem::E1 e3 = #C9;
    const constructor •(core::int index, core::String name) → sem::E1
      : super core::_Enum::•(index, name)
      ;
    method toString() → core::String
      return "E1.${this.{core::_Enum::_name}{core::String}}";
  }

/cc @chloestefantsova @johnniwinther

@alexmarkov alexmarkov added the legacy-area-front-end Legacy: Use area-dart-model instead. label Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

2 participants