Macro. Report MACRO_APPLICATION_ARGUMENT_ERROR.

Change-Id: I81a65a0f9d5f40c4c630674e0957f01fa9c2c44d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350162
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
index db5a305..f67f0d9 100644
--- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
+++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
@@ -1037,6 +1037,8 @@
   status: noFix
 CompileTimeErrorCode.MACRO_DECLARATIONS_PHASE_INTROSPECTION_CYCLE:
   status: needsEvaluation
+CompileTimeErrorCode.MACRO_APPLICATION_ARGUMENT_ERROR:
+  status: noFix
 CompileTimeErrorCode.MACRO_ERROR:
   status: noFix
 CompileTimeErrorCode.MAIN_FIRST_POSITIONAL_PARAMETER_TYPE:
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart
index 0d560e5..9924175 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -3037,6 +3037,14 @@
   );
 
   ///  Parameters:
+  ///  0: the message
+  static const CompileTimeErrorCode MACRO_APPLICATION_ARGUMENT_ERROR =
+      CompileTimeErrorCode(
+    'MACRO_APPLICATION_ARGUMENT_ERROR',
+    "{0}",
+  );
+
+  ///  Parameters:
   ///  0: the name of the introspected declaration
   static const CompileTimeErrorCode
       MACRO_DECLARATIONS_PHASE_INTROSPECTION_CYCLE = CompileTimeErrorCode(
diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/error/error_code_values.g.dart
index b9c3e24..01f16db 100644
--- a/pkg/analyzer/lib/src/error/error_code_values.g.dart
+++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart
@@ -323,6 +323,7 @@
   CompileTimeErrorCode.LATE_FINAL_FIELD_WITH_CONST_CONSTRUCTOR,
   CompileTimeErrorCode.LATE_FINAL_LOCAL_ALREADY_ASSIGNED,
   CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE,
+  CompileTimeErrorCode.MACRO_APPLICATION_ARGUMENT_ERROR,
   CompileTimeErrorCode.MACRO_DECLARATIONS_PHASE_INTROSPECTION_CYCLE,
   CompileTimeErrorCode.MACRO_ERROR,
   CompileTimeErrorCode.MAIN_FIRST_POSITIONAL_PARAMETER_TYPE,
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 7ca684e..de14af7 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -6217,8 +6217,13 @@
     for (final diagnostic in element.macroDiagnostics) {
       switch (diagnostic) {
         case ArgumentMacroDiagnostic():
-          // TODO(scheglov): implement
-          throw UnimplementedError();
+          var annotation = metadata[diagnostic.annotationIndex];
+          var arguments = annotation.arguments!.arguments;
+          errorReporter.atNode(
+            arguments[diagnostic.argumentIndex],
+            CompileTimeErrorCode.MACRO_APPLICATION_ARGUMENT_ERROR,
+            arguments: [diagnostic.message],
+          );
         case DeclarationsIntrospectionCycleDiagnostic():
           var messages = diagnostic.components.map<DiagnosticMessage>(
             (component) {
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 05290fd..fee05f4 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -9532,6 +9532,11 @@
       ```dart
       List<num> x = [1, 2.5, 3];
       ```
+  MACRO_APPLICATION_ARGUMENT_ERROR:
+    problemMessage: "{0}"
+    comment: |-
+      Parameters:
+      0: the message
   MACRO_ERROR:
     problemMessage: "{0}"
     comment: |-
diff --git a/pkg/analyzer/test/src/dart/resolution/macro_test.dart b/pkg/analyzer/test/src/dart/resolution/macro_test.dart
index dc2fbb3..d9d2278 100644
--- a/pkg/analyzer/test/src/dart/resolution/macro_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/macro_test.dart
@@ -291,6 +291,17 @@
     ]);
   }
 
+  test_diagnostic_report_argumentError_instanceCreation() async {
+    await assertErrorsInCode('''
+import 'diagnostic.dart';
+
+@MacroWithArguments(0, const Object())
+class A {}
+''', [
+      error(CompileTimeErrorCode.MACRO_APPLICATION_ARGUMENT_ERROR, 50, 14),
+    ]);
+  }
+
   test_diagnostic_report_atDeclaration_class_error() async {
     await assertErrorsInCode('''
 import 'diagnostic.dart';
diff --git a/pkg/analyzer/test/src/summary/macro/diagnostic.dart b/pkg/analyzer/test/src/summary/macro/diagnostic.dart
index 87b25eb..f0e8412 100644
--- a/pkg/analyzer/test/src/summary/macro/diagnostic.dart
+++ b/pkg/analyzer/test/src/summary/macro/diagnostic.dart
@@ -4,6 +4,16 @@
 
 import 'package:_fe_analyzer_shared/src/macros/api.dart';
 
+/*macro*/ class MacroWithArguments implements ClassDeclarationsMacro {
+  final Object? a1;
+  final Object? a2;
+
+  const MacroWithArguments(this.a1, this.a2);
+
+  @override
+  buildDeclarationsForClass(declaration, builder) {}
+}
+
 /*macro*/ class ReportAtFirstMethod implements ClassDeclarationsMacro {
   const ReportAtFirstMethod();