Skip to content
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

EnumClass code generation does not support Dart 2.17 super syntax #1147

Closed
maxlapides opened this issue May 12, 2022 · 6 comments · Fixed by #1178
Closed

EnumClass code generation does not support Dart 2.17 super syntax #1147

maxlapides opened this issue May 12, 2022 · 6 comments · Fixed by #1178
Assignees

Comments

@maxlapides
Copy link
Contributor

maxlapides commented May 12, 2022

Currently, built_value expects EnumClasses to look like this:

class TestEnum extends EnumClass {
  const TestEnum._(String name) : super(name);

  static Serializer<TestEnum> get serializer => _$testEnumSerializer;

  static const TestEnum yes = _$yes;
  static const TestEnum no = _$no;
  static const TestEnum maybe = _$maybe;

  static BuiltSet<TestEnum> get values => _$values;
  static TestEnum valueOf(String name) => _$valueOf(name);
}

As of Dart 2.17, you can rewrite that like this:

class TestEnum extends EnumClass {
  const TestEnum._(super.name);

  static Serializer<TestEnum> get serializer => _$testEnumSerializer;

  static const TestEnum yes = _$yes;
  static const TestEnum no = _$no;
  static const TestEnum maybe = _$maybe;

  static BuiltSet<TestEnum> get values => _$values;
  static TestEnum valueOf(String name) => _$valueOf(name);
}

But, this produces an error during code generation:

Please make the following changes to use EnumClass:

1. Have exactly one constructor: const TestEnum._(String name) : super(name);
@davidmorgan
Copy link
Collaborator

Thanks!

2.17 also adds enums that support code, which should mostly make EnumClass unnecessary ... except that we'll still want them to be serializable. I need to take a deeper look...

@Rimantovas
Copy link

Is there a workaround?

@davidmorgan
Copy link
Collaborator

No, you'll have to write it the old way for now.

@kuhnroyal
Copy link
Contributor

@davidmorgan Do you think you can find a quick way to allow the super syntax when you cut a release?

@davidmorgan
Copy link
Collaborator

Done :) will be released in 8.4.0 today. Thanks for commenting :)

@kuhnroyal
Copy link
Contributor

Awesome, thanks!

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

Successfully merging a pull request may close this issue.

4 participants