google/built_value.dart

`enum_source_class.dart` contains faulty mixin code in dart 3

ahmednfwela opened this issue · 7 comments

this file
https://github.com/google/built_value.dart/blob/master/built_value_generator/lib/src/enum_source_class.dart#L184

checks code similar to this

abstract class AMixin = Object with _$AMixin;

which uses the generated code:

abstract class _$AMixin {
  // ignore: non_constant_identifier_names
  _$AMeta get A => const _$AMeta();
}

which in dart 3 causes compile-time error

The class '_$AMixin' can't be used as a mixin because it's neither a mixin class nor a mixin.dart class_used_as_mixin

faulty line: https://github.com/google/built_value.dart/blob/master/built_value_generator/lib/src/enum_source_class.dart#LL247C11-L247C11

should be

-      ..writeln('abstract class _\$${name}Mixin {')
+      ..writeln('mixin _\$${name}Mixin {')

cc @davidmorgan

I'm not sure if we ever announced this feature, it was for use with Angular templates--is that where you're using it?

I didn't fix it because I thought possibly nobody was using it any more :) but if it still does something useful I can take a look. Thanks.

it's used by the "dart-dio" openapi-generator and is generated for all enums in a spec, so yes I think it will be useful 😊

Good to know! Any chance you could point to an example, please? That way I can make sure it still works as intended for that use case. Thanks.

Hi @ahmednfwela

I think #1253 should do it. Unfortunately, code using built_value will need an update, as the old way class TestEnumMixin = Object with _$TestEnumMixin is not valid as a mixin in Dart 3.

Instead I think the right way is typedef TestEnumMixin = _$TestEnumMixin, so my PR adds triggering of generation based on this.

What do you think, please?

Thanks.

looks good! thanks for fixing it

Released in 8.6.1. Thanks again for reporting! Please let me know if you hit any further issues.