Skip to content

[Enhanced enums] Runtime error when printing enum with mixin #48303

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
sgrekhov opened this issue Feb 4, 2022 · 2 comments
Closed

[Enhanced enums] Runtime error when printing enum with mixin #48303

sgrekhov opened this issue Feb 4, 2022 · 2 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Feb 4, 2022

The following code produces runtime error

mixin M1 on Enum {
  int mixedInMethod1(int v) => v;
}

enum E with M1 {
  e1,
  e2,
  e3;
}

main() {
  print(E.e1);
}

Output is

Unhandled exception:
Invalid argument (object): toString method returned 'null': Instance of 'E'
#0      _StringBase._interpolateSingle (dart:core-patch/string_patch.dart:834:7)
#1      print (dart:core/print.dart:9:26)
#2      main (file:///C:/Users/sgrek/Work/Google/co19/LanguageFeatures/Enhanced-Enum/semantics_A03_t05.dart:47:3)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

Process finished with exit code 255

Tested on Dart SDK version: 2.17.0-69.0.dev (dev) (Fri Jan 28 00:44:27 2022 -0800) on "windows_x64"

@kevmoo kevmoo added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. legacy-area-front-end Legacy: Use area-dart-model instead. labels Feb 4, 2022
@a-siva
Copy link
Contributor

a-siva commented Feb 4, 2022

//cc @alexmarkov

@alexmarkov
Copy link
Contributor

For some reason CFE didn't generate the body of toString method in E. The empty body just returns null, hence the exception is thrown.

Kernel:

  abstract class M1 extends core::Enum /*isMixinDeclaration*/  {
    method mixedInMethod1(core::int v) → core::int
      return v;
  }
  abstract class _E&_Enum&M1 extends core::_Enum implements tes::M1 /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/  {
    const synthetic constructor •(core::int index, core::String _name) → tes::_E&_Enum&M1
      : super core::_Enum::•(index, _name)
      ;
    method mixedInMethod1(core::int v) → core::int
      return v;
  }
  class E extends tes::_E&_Enum&M1 /*isEnum*/  {
    static const field core::List<tes::E> values = #C10;
    static const field tes::E e1 = #C3;
    static const field tes::E e2 = #C6;
    static const field tes::E e3 = #C9;
    const constructor •(core::int index, core::String name) → tes::E
      : super tes::_E&_Enum&M1::•(index, name)
      ;
    method toString() → core::String
      ;
  }
  static method main() → dynamic {
    core::print(#C3);
  }

@chloestefantsova Could you please take a look?

@alexmarkov alexmarkov removed the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Feb 5, 2022
@chloestefantsova chloestefantsova self-assigned this Feb 7, 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

5 participants