From ce239bcb3a9eb21885075be7ffe76c657c47c762 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 17 May 2024 19:14:50 -0500 Subject: [PATCH] feat: throw if a default constructor already exists --- lib/src/constructable_macro.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/constructable_macro.dart b/lib/src/constructable_macro.dart index a29e4e2..94a60eb 100644 --- a/lib/src/constructable_macro.dart +++ b/lib/src/constructable_macro.dart @@ -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(