Skip to content

Commit

Permalink
- Fixed unexpected avoid_unnecessary_type_assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
DerhachevAndrii committed Mar 14, 2024
1 parent 46026f7 commit 6b94de7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/src/utils/typecast_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TypeCast {

final objectCastedType = castTypeInHierarchy();
if (objectCastedType == null) {
return isReversed;
return false;
}

final objectTypeCast = TypeCast(
Expand All @@ -77,7 +77,7 @@ class TypeCast {
if (!objectTypeCast.areGenericsWithSameTypeArgs) {
return false;
}

return !isReversed;
}

Expand Down
13 changes: 12 additions & 1 deletion lint_test/avoid_unnecessary_type_assertions_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: prefer_const_declarations
// ignore_for_file: prefer_const_declarations, prefer_match_file_name, unused_element
// ignore_for_file: unnecessary_nullable_for_final_variable_declarations
// ignore_for_file: unnecessary_type_check
// ignore_for_file: unused_local_variable
Expand Down Expand Up @@ -34,3 +34,14 @@ void fun() {
// casting `Type? is Type` is allowed
final castedD = nullableD is double;
}

class _A {}

class _B extends _A {}

class _C extends _A {}

void noLint() {
final _A a = _B();
if (a is! _C) return;
}

0 comments on commit 6b94de7

Please sign in to comment.