quick fix for MISSING_TYPEDEF_PARAMETERS

See: https://github.com/dart-lang/sdk/issues/55917

Change-Id: I9b81940c1c515bf923ceecb83d5aaad1d416dab1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370482
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
pq 2024-06-11 08:03:15 +00:00 committed by Commit Queue
parent 49e0c0b33e
commit 7ead4b5786
4 changed files with 23 additions and 6 deletions

View file

@ -24,10 +24,17 @@ class AddEmptyArgumentList extends ResolvedCorrectionProducer {
@override
Future<void> compute(ChangeBuilder builder) async {
var node = this.node;
if (node is! AnnotationImpl) return;
int? offset;
if (node is AnnotationImpl) {
offset = node.end;
} else if (node is FunctionTypeAlias) {
// endToken is the trailing `;`.
offset = node.endToken.previous?.end;
}
if (offset == null) return;
await builder.addDartFileEdit(file, (builder) {
builder.addSimpleInsertion(node.end, '()');
builder.addSimpleInsertion(offset!, '()');
});
}
}

View file

@ -45,7 +45,7 @@
#
# Stats:
# - 42 "needsEvaluation"
# - 334 "needsFix"
# - 331 "needsFix"
# - 417 "hasFix"
# - 516 "noFix"
@ -3060,9 +3060,7 @@ ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP:
notes: |-
Add the missing terminator.
ParserErrorCode.MISSING_TYPEDEF_PARAMETERS:
status: needsFix
notes: |-
Add an empty parameter list.
status: hasFix
ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH:
status: noFix
ParserErrorCode.MIXED_PARAMETER_GROUPS:

View file

@ -1452,6 +1452,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
ParserErrorCode.MISSING_FUNCTION_BODY: [
ConvertIntoBlockBody.missingBody,
],
ParserErrorCode.MISSING_TYPEDEF_PARAMETERS: [
AddEmptyArgumentList.new,
],
ParserErrorCode.MIXIN_DECLARES_CONSTRUCTOR: [
RemoveConstructor.new,
],

View file

@ -61,6 +61,15 @@ class A {
}
@A()
main() {}
''');
}
Future<void> test_missingTypedefParameters() async {
await resolveTestCode('''
typedef F<E>;
''');
await assertHasFix('''
typedef F<E>();
''');
}
}