Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1489)

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1422813003: Add hint for use of ?. in conditions (issue 24649) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add checks for asserts, and conditional expressions Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 13391621d600e696f99fcba19c1de5047d8cae25..a74a1d6e85d514da8fe7a67cbb815e00bcc84120 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -3153,6 +3153,149 @@ class A {
verify([source]);
}
+ void test_nullAwareInCondition_assert() {
+ Source source = addSource(r'''
+m(x) {
+ assert (x?.a);
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_conditionalExpression() {
+ Source source = addSource(r'''
+m(x) {
+ return x?.a ? 0 : 1;
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_do() {
+ Source source = addSource(r'''
+m(x) {
+ do {} while (x?.a);
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_for() {
+ Source source = addSource(r'''
+m(x) {
+ for (var v = x; v?.a; v = v.next) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if() {
+ Source source = addSource(r'''
+m(x) {
+ if (x?.a) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_conditionalAnd_first() {
+ Source source = addSource(r'''
+m(x) {
+ if (x?.a && x.b) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_conditionalAnd_second() {
+ Source source = addSource(r'''
+m(x) {
+ if (x.a && x?.b) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_conditionalAnd_third() {
+ Source source = addSource(r'''
+m(x) {
+ if (x.a && x.b && x?.c) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_conditionalOr_first() {
+ Source source = addSource(r'''
+m(x) {
+ if (x?.a || x.b) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_conditionalOr_second() {
+ Source source = addSource(r'''
+m(x) {
+ if (x.a || x?.b) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_conditionalOr_third() {
+ Source source = addSource(r'''
+m(x) {
+ if (x.a || x.b || x?.c) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_parenthesized() {
+ Source source = addSource(r'''
+m(x) {
+ if ((x?.a)) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_while() {
+ Source source = addSource(r'''
+m(x) {
+ while (x?.a) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
+ verify([source]);
+ }
+
void test_overrideOnNonOverridingGetter_invalid() {
Source source = addSource(r'''
library dart.core;
@@ -6900,6 +7043,28 @@ abstract class A {
verify([source]);
}
+ void test_nullAwareInCondition_for_noCondition() {
+ Source source = addSource(r'''
+m(x) {
+ for (var v = x; ; v++) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_nullAwareInCondition_if_notTopLevel() {
+ Source source = addSource(r'''
+m(x) {
+ if (x?.y == null) {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
void test_overrideEqualsButNotHashCode() {
Source source = addSource(r'''
class A {
« pkg/analyzer/lib/src/generated/error.dart ('K') | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698