Open Sadhorsephile opened 3 months ago
Summary: The user's macro generates constructors based on field annotations, but it fails to generate a constructor with the correct number of positional arguments. The macro incorrectly identifies the number of required positional arguments, leading to an error when attempting to instantiate the class.
Annotations also don't work in such cases (when used on function parameters):
external Future<PostEntity> createPost(@Body() String post);
Problem
I wrote macro to automatically generate constructors for classes. It uses annotations to determine which fields should be named, positional and required.
Macro code
```dart import 'dart:async'; import 'package:collection/collection.dart'; import 'package:macros/macros.dart'; macro class AutoConstructor implements ClassDeclarationsMacro { const AutoConstructor(); @override FutureOrAnnotations code
```dart class NamedParamExample
```dart import 'package:test_macros/1.%20auto_constructor/annotations.dart'; import 'package:test_macros/1.%20auto_constructor/auto_constructor.dart'; @AutoConstructor() class AnotherComplicatedClass { final int a; @requiredField @NamedParam() final String b; @NamedParam(defaultValue: 3.14) final double c; @NamedParam() final bool? d; @requiredField @NamedParam() final bool? e; final ListExample (augmentation)
```dart augment library 'package:test_macros/1.%20auto_constructor/example.dart'; augment class AnotherComplicatedClass { AnotherComplicatedClass( this.a, this.f, { required this.b, this.c = 3.14, this.d, required this.e, } ); } ```There are no errors from the analyzer, but I can't launch this code due to the following error:
At the same time, this code works if I remove all the field annotations from the class.
Additional info
dart info
output: