Skip to content

Commit

Permalink
fix prefer_void_to_null false positive on extension type representa…
Browse files Browse the repository at this point in the history
…tions

Fixes: https://github.com/dart-lang/linter/issues/4720

Change-Id: Ie3a736cbd4d190135eb77932ec8ba9352683226e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
pq authored and Commit Queue committed Oct 11, 2023
1 parent 985c292 commit d9731ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/linter/lib/src/rules/prefer_void_to_null.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class _Visitor extends SimpleAstVisitor<void> {
return;
}

// extension type N(Null _) ...
if (parent is RepresentationDeclaration) {
return;
}

// https://github.com/dart-lang/linter/issues/2792
if (parent is MethodDeclaration &&
isVoidIncompatibleOverride(parent, node)) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/linter/test/rules/prefer_void_to_null_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ void f(int a) {
]);
}

/// https://github.com/dart-lang/linter/issues/4759
test_extensionTypeRepresentation() async {
await assertNoDiagnostics(r'''
extension type B<T>(T? _) {}
extension type N(Null _) implements B<Never> {}
''');
}

test_localVariable() async {
await assertNoDiagnostics(r'''
void f() {
Expand Down

0 comments on commit d9731ac

Please sign in to comment.