Skip to content

Commit

Permalink
Fix false positive fix remove ?
Browse files Browse the repository at this point in the history
Closes #57068

GitOrigin-RevId: e875cd4
Change-Id: I00f3445a240dc1d92ddba6e7e4f42ecf5bb907d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394403
Reviewed-by: Paul Berry <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
  • Loading branch information
tenhobi authored and Commit Queue committed Nov 13, 2024
1 parent 81c7964 commit 901b2eb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ class TypeSystemOperations
@override
TypeClassification classifyType(SharedTypeView<DartType> type) {
DartType unwrapped = type.unwrapTypeView();
if (isSubtypeOfInternal(unwrapped, typeSystem.typeProvider.objectType)) {
if (type is InvalidType) {
return TypeClassification.potentiallyNullable;
} else if (isSubtypeOfInternal(
unwrapped, typeSystem.typeProvider.objectType)) {
return TypeClassification.nonNullable;
} else if (isSubtypeOfInternal(
unwrapped, typeSystem.typeProvider.nullType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main() {

@reflectiveTest
class UnnecessaryNullAssertPatternTest extends PubPackageResolutionTest {
test_interfaceType_nonNullable() async {
Future<void> test_interfaceType_nonNullable() async {
await assertErrorsInCode('''
void f(int x) {
if (x case var a!) {}
Expand All @@ -26,7 +26,7 @@ void f(int x) {
]);
}

test_interfaceType_nullable() async {
Future<void> test_interfaceType_nullable() async {
await assertErrorsInCode('''
void f(int? x) {
if (x case var a!) {}
Expand All @@ -36,7 +36,34 @@ void f(int? x) {
]);
}

test_typeParameter_nonNullable() async {
Future<void> test_invalidType_nonNullable() async {
await assertErrorsInCode('''
UnknownType getValue() => UnknownType();
void f() {
if (getValue() case final valueX!) {
print(valueX);
}
}
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 0, 11),
error(CompileTimeErrorCode.UNDEFINED_FUNCTION, 26, 11),
]);
}

Future<void> test_invalidType_nullable() async {
await assertErrorsInCode('''
UnknownType? getValue() => null;
void f() {
if (getValue() case final valueX!) {
print(valueX);
}
}
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 0, 11),
]);
}

Future<void> test_typeParameter_nonNullable() async {
await assertErrorsInCode('''
class A<T extends num> {
void f(T x) {
Expand All @@ -49,7 +76,7 @@ class A<T extends num> {
]);
}

test_typeParameter_nullable() async {
Future<void> test_typeParameter_nullable() async {
await assertErrorsInCode('''
class A<T> {
void f(T x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main() {

@reflectiveTest
class UnnecessaryNullCheckPatternTest extends PubPackageResolutionTest {
test_interfaceType_nonNullable() async {
Future<void> test_interfaceType_nonNullable() async {
await assertErrorsInCode('''
void f(int x) {
if (x case var a?) {}
Expand All @@ -26,7 +26,7 @@ void f(int x) {
]);
}

test_interfaceType_nullable() async {
Future<void> test_interfaceType_nullable() async {
await assertErrorsInCode('''
void f(int? x) {
if (x case var a?) {}
Expand All @@ -36,7 +36,34 @@ void f(int? x) {
]);
}

test_typeParameter_nonNullable() async {
Future<void> test_invalidType_nonNullable() async {
await assertErrorsInCode('''
UnknownType getValue() => UnknownType();
void f() {
if (getValue() case final valueX?) {
print(valueX);
}
}
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 0, 11),
error(CompileTimeErrorCode.UNDEFINED_FUNCTION, 26, 11),
]);
}

Future<void> test_invalidType_nullable() async {
await assertErrorsInCode('''
UnknownType? getValue() => null;
void f() {
if (getValue() case final valueX?) {
print(valueX);
}
}
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 0, 11),
]);
}

Future<void> test_typeParameter_nonNullable() async {
await assertErrorsInCode('''
class A<T extends num> {
void f(T x) {
Expand All @@ -49,7 +76,7 @@ class A<T extends num> {
]);
}

test_typeParameter_nullable() async {
Future<void> test_typeParameter_nullable() async {
await assertErrorsInCode('''
class A<T> {
void f(T x) {
Expand Down

0 comments on commit 901b2eb

Please sign in to comment.