Skip to content

Commit 78b1e15

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Don't report NULLABLE_TYPE_IN_CATCH_CLAUSE in opt-out libraries.
R=brianwilkerson@google.com, paulberry@google.com Change-Id: Iabd6a4b23c81e25bc7045db6d562c38567c81921 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135522 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 60295a2 commit 78b1e15

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
426426
try {
427427
_isInCatchClause = true;
428428
_checkForTypeAnnotationDeferredClass(node.exceptionType);
429-
_checkForPotentiallyNullableType(node.exceptionType);
429+
_checkForNullableTypeInCatchClause(node.exceptionType);
430430
super.visitCatchClause(node);
431431
} finally {
432432
_isInCatchClause = previousIsInCatchClause;
@@ -3941,6 +3941,23 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
39413941
}
39423942
}
39433943

3944+
void _checkForNullableTypeInCatchClause(TypeAnnotation type) {
3945+
if (!_isNonNullableByDefault) {
3946+
return;
3947+
}
3948+
3949+
if (type == null) {
3950+
return;
3951+
}
3952+
3953+
if (_typeSystem.isPotentiallyNullable(type.type)) {
3954+
_errorReporter.reportErrorForNode(
3955+
CompileTimeErrorCode.NULLABLE_TYPE_IN_CATCH_CLAUSE,
3956+
type,
3957+
);
3958+
}
3959+
}
3960+
39443961
/**
39453962
* Verify that all classes of the given [onClause] are valid.
39463963
*
@@ -4045,18 +4062,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
40454062
}
40464063
}
40474064

4048-
/**
4049-
* Verify that the [type] is not potentially nullable.
4050-
*/
4051-
void _checkForPotentiallyNullableType(TypeAnnotation type) {
4052-
if (_options.experimentStatus.non_nullable &&
4053-
type?.type != null &&
4054-
_typeSystem.isPotentiallyNullable(type.type)) {
4055-
_errorReporter.reportErrorForNode(
4056-
CompileTimeErrorCode.NULLABLE_TYPE_IN_CATCH_CLAUSE, type);
4057-
}
4058-
}
4059-
40604065
/**
40614066
* Check that the given named optional [parameter] does not begin with '_'.
40624067
*

pkg/analyzer/test/src/diagnostics/nullable_type_in_catch_clause_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ class A<B extends Object> {
8383
}
8484
}
8585
}
86+
''');
87+
}
88+
89+
test_optOut() async {
90+
await assertNoErrorsInCode('''
91+
// @dart = 2.7
92+
93+
void f() {
94+
try {
95+
} on dynamic {
96+
}
97+
}
8698
''');
8799
}
88100
}

0 commit comments

Comments
 (0)