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>
This commit is contained in:
Konstantin Shcheglov 2024-02-05 17:40:39 +00:00 committed by Commit Queue
parent 11e4f4574f
commit a10b584b68
7 changed files with 44 additions and 2 deletions

View file

@ -1037,6 +1037,8 @@ CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE:
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:

View file

@ -3036,6 +3036,14 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// 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

View file

@ -323,6 +323,7 @@ const List<ErrorCode> errorCodeValues = [
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,

View file

@ -6217,8 +6217,13 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
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) {

View file

@ -9532,6 +9532,11 @@ CompileTimeErrorCode:
```dart
List<num> x = [1, 2.5, 3];
```
MACRO_APPLICATION_ARGUMENT_ERROR:
problemMessage: "{0}"
comment: |-
Parameters:
0: the message
MACRO_ERROR:
problemMessage: "{0}"
comment: |-

View file

@ -291,6 +291,17 @@ class A {
]);
}
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';

View file

@ -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();