Skip to content

Commit

Permalink
feat: throw if a default constructor already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed May 18, 2024
1 parent b627783 commit ce239bc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/src/constructable_macro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ macro class Constructable implements ClassDeclarationsMacro {
ClassDeclaration clazz,
MemberDeclarationBuilder builder,
) async {
final constructors = await builder.constructorsOf(clazz);
if (constructors.any((c) => c.identifier.name == '')) {
throw ArgumentError('A default constructor already exists.');
}

final fieldDeclarations = await builder.fieldsOf(clazz);
final fields = await Future.wait(
fieldDeclarations.map(
Expand Down

0 comments on commit ce239bc

Please sign in to comment.