Skip to content

Commit f36297e

Browse files
bwilkersonCommit Queue
authored andcommitted
Fix an exception in a lint rule
Fixes #60927 Change-Id: I042adc05b7ff237aa7316f4cd101e0ffb5f33fb4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435244 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 0bb629e commit f36297e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/dartdev/test/commands/fix_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,33 @@ linter:
629629
});
630630
});
631631

632+
group('regression', () {
633+
test('field without name', () async {
634+
// This is a test for https://github.com/dart-lang/sdk/issues/60927.
635+
p = project(
636+
mainSrc: '''
637+
class C {
638+
int? a,;
639+
}
640+
''',
641+
analysisOptions: '''
642+
linter:
643+
rules:
644+
- prefer_final_fields
645+
''',
646+
);
647+
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
648+
expect(result.exitCode, 0);
649+
expect(result.stderr, isEmpty);
650+
expect(
651+
result.stdout,
652+
stringContainsInOrderWithVariableBullets([
653+
'Computing fixes in myapp...',
654+
'Nothing to fix!',
655+
]));
656+
});
657+
});
658+
632659
group('compare-to-golden', () {
633660
test('target is not a directory', () async {
634661
p = project(

pkg/linter/lib/src/rules/prefer_final_fields.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class _DeclarationsCollector extends RecursiveAstVisitor<void> {
5252
for (var variable in node.fields.variables) {
5353
var element = variable.declaredFragment?.element;
5454
if (element is FieldElement &&
55+
element.name3 != null &&
5556
element.isPrivate &&
5657
!overridesField(element)) {
5758
fields[element] = variable;

0 commit comments

Comments
 (0)