xsahil03x / super_enum

Create super-powered dart enums similar to sealed classes in Kotlin
https://pub.dev/packages/super_enum
MIT License
116 stars 13 forks source link

DataFields with a name including 'T' break code generation #39

Closed WanderingFire2001 closed 4 years ago

WanderingFire2001 commented 4 years ago

Latest update (0.4.0, released several hours ago) has a very bad bug.

Any data field with a capital 'T' in the name appears to break code generation, yielding the standard comment header and the single line: /*State must be annotated with @generic*/

To reproduce:

The following works properly -- exactly as you would expect:

import 'package:super_enum/super_enum.dart';

part 'super_enum_sample.g.dart';

class SomeVee {
  String data;
}

@superEnum
enum _StatesGood {
  @Data(fields: [
    DataField<SomeVee>('fieldName'),
  ])
  State
}

The following fails, and is the same other than the type of field, now being SomeTee instead of SomeVee (T in the name vs no T in the name).

import 'package:super_enum/super_enum.dart';

part 'super_enum_sample.g.dart';

class SomeTee {
  String data;
}

@superEnum
enum _StatesBad {
  @Data(fields: [
    DataField<SomeTee>('fieldName'),
  ])
  State
}

The problem stems from line 377 of class_generator.dart

    if (_classFields
        .any((e) => type_processor.dataFieldType(e).contains('T'))) {
      if (!isGeneric) {
        throw InvalidGenerationSourceError(
            '${field.name} must be annotated with @generic');
      }
    }

(Hairy debug session to find this... 'my T' was in a complex type using built values and I had a lot of suspicions to track down before I got to "does it include a capital T' ;-)

Love all the new features, thanks for all your hard work!

astralstriker commented 4 years ago

That's a very bad bug indeed. Thanks for letting us know. Will fix this on an urgent basis. Sorry that you had to go through that rigorous debugging.