Issue 52060. Fix reporting CONSTANT_PATTERN_NEVER_MATCHES_VALUE_TYPE for Null vs. nullable FunctionType.

Bug: https://github.com/dart-lang/sdk/issues/52060
Change-Id: I5373a9a73396fbf49562131f5f801d1bceeb65f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298280
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-04-25 20:09:28 +00:00 committed by Commit Queue
parent b81fd66ed5
commit 00d841ee99
2 changed files with 21 additions and 0 deletions

View file

@ -478,6 +478,9 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
return _canBeEqual(constantType, bound);
}
} else if (valueType is FunctionType) {
if (constantType.isDartCoreNull) {
return _typeSystem.isNullable(valueType);
}
return false;
}
}

View file

@ -356,6 +356,24 @@ void f(String x) {
]);
}
test_Null_functionType() async {
await assertErrorsInCode('''
void f(void Function() x) {
if (x case (null)) {}
}
''', [
error(WarningCode.CONSTANT_PATTERN_NEVER_MATCHES_VALUE_TYPE, 42, 4),
]);
}
test_Null_functionTypeQuestion() async {
await assertNoErrorsInCode('''
void f(void Function()? x) {
if (x case (null)) {}
}
''');
}
test_Null_int() async {
await assertErrorsInCode('''
void f(int x) {