Fix a bug in convertDefaultToPrimaryConstructor
The convertDefaultToPrimaryConstructor fix wasn't accounting for the presence of type parameters when choosing where to insert the empty parentheses. This fixes that. Closes https://github.com/dart-lang/sdk/issues/63482 Change-Id: Ibec4f5531840bf0c0aafa4436654201ef8a8a6ec Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508202 Reviewed-by: Samuel Rawlins <srawlins@google.com> Auto-Submit: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
+4
-1
@@ -38,7 +38,10 @@ class ConvertDefaultToPrimaryConstructor extends ResolvedCorrectionProducer {
|
||||
if (namePart is! PrimaryConstructorDeclaration &&
|
||||
(!members.any((e) => e is ConstructorDeclaration))) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(namePart.typeName.end, '()');
|
||||
builder.addSimpleInsertion(
|
||||
namePart.typeParameters?.end ?? namePart.typeName.end,
|
||||
'()',
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -31,6 +31,15 @@ class C();
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_class_withDefaultConstructor() async {
|
||||
await resolveTestCode('''
|
||||
class C<T> {}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
class C<T>() {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_enum() async {
|
||||
await resolveTestCode('''
|
||||
enum E^ {
|
||||
|
||||
Reference in New Issue
Block a user