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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/context.dart' as newContext; 9 import 'package:analyzer/src/context/context.dart' as newContext;
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 3135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3146 void test_missingReturn_method() { 3146 void test_missingReturn_method() {
3147 Source source = addSource(r''' 3147 Source source = addSource(r'''
3148 class A { 3148 class A {
3149 int m() {} 3149 int m() {}
3150 }'''); 3150 }''');
3151 computeLibrarySourceErrors(source); 3151 computeLibrarySourceErrors(source);
3152 assertErrors(source, [HintCode.MISSING_RETURN]); 3152 assertErrors(source, [HintCode.MISSING_RETURN]);
3153 verify([source]); 3153 verify([source]);
3154 } 3154 }
3155 3155
3156 void test_nullAwareInCondition_assert() {
3157 Source source = addSource(r'''
3158 m(x) {
3159 assert (x?.a);
3160 }
3161 ''');
3162 computeLibrarySourceErrors(source);
3163 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3164 verify([source]);
3165 }
3166
3167 void test_nullAwareInCondition_conditionalExpression() {
3168 Source source = addSource(r'''
3169 m(x) {
3170 return x?.a ? 0 : 1;
3171 }
3172 ''');
3173 computeLibrarySourceErrors(source);
3174 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3175 verify([source]);
3176 }
3177
3178 void test_nullAwareInCondition_do() {
3179 Source source = addSource(r'''
3180 m(x) {
3181 do {} while (x?.a);
3182 }
3183 ''');
3184 computeLibrarySourceErrors(source);
3185 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3186 verify([source]);
3187 }
3188
3189 void test_nullAwareInCondition_for() {
3190 Source source = addSource(r'''
3191 m(x) {
3192 for (var v = x; v?.a; v = v.next) {}
3193 }
3194 ''');
3195 computeLibrarySourceErrors(source);
3196 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3197 verify([source]);
3198 }
3199
3200 void test_nullAwareInCondition_if() {
3201 Source source = addSource(r'''
3202 m(x) {
3203 if (x?.a) {}
3204 }
3205 ''');
3206 computeLibrarySourceErrors(source);
3207 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3208 verify([source]);
3209 }
3210
3211 void test_nullAwareInCondition_if_conditionalAnd_first() {
3212 Source source = addSource(r'''
3213 m(x) {
3214 if (x?.a && x.b) {}
3215 }
3216 ''');
3217 computeLibrarySourceErrors(source);
3218 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3219 verify([source]);
3220 }
3221
3222 void test_nullAwareInCondition_if_conditionalAnd_second() {
3223 Source source = addSource(r'''
3224 m(x) {
3225 if (x.a && x?.b) {}
3226 }
3227 ''');
3228 computeLibrarySourceErrors(source);
3229 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3230 verify([source]);
3231 }
3232
3233 void test_nullAwareInCondition_if_conditionalAnd_third() {
3234 Source source = addSource(r'''
3235 m(x) {
3236 if (x.a && x.b && x?.c) {}
3237 }
3238 ''');
3239 computeLibrarySourceErrors(source);
3240 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3241 verify([source]);
3242 }
3243
3244 void test_nullAwareInCondition_if_conditionalOr_first() {
3245 Source source = addSource(r'''
3246 m(x) {
3247 if (x?.a || x.b) {}
3248 }
3249 ''');
3250 computeLibrarySourceErrors(source);
3251 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3252 verify([source]);
3253 }
3254
3255 void test_nullAwareInCondition_if_conditionalOr_second() {
3256 Source source = addSource(r'''
3257 m(x) {
3258 if (x.a || x?.b) {}
3259 }
3260 ''');
3261 computeLibrarySourceErrors(source);
3262 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3263 verify([source]);
3264 }
3265
3266 void test_nullAwareInCondition_if_conditionalOr_third() {
3267 Source source = addSource(r'''
3268 m(x) {
3269 if (x.a || x.b || x?.c) {}
3270 }
3271 ''');
3272 computeLibrarySourceErrors(source);
3273 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3274 verify([source]);
3275 }
3276
3277 void test_nullAwareInCondition_if_parenthesized() {
3278 Source source = addSource(r'''
3279 m(x) {
3280 if ((x?.a)) {}
3281 }
3282 ''');
3283 computeLibrarySourceErrors(source);
3284 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3285 verify([source]);
3286 }
3287
3288 void test_nullAwareInCondition_while() {
3289 Source source = addSource(r'''
3290 m(x) {
3291 while (x?.a) {}
3292 }
3293 ''');
3294 computeLibrarySourceErrors(source);
3295 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3296 verify([source]);
3297 }
3298
3156 void test_overrideOnNonOverridingGetter_invalid() { 3299 void test_overrideOnNonOverridingGetter_invalid() {
3157 Source source = addSource(r''' 3300 Source source = addSource(r'''
3158 library dart.core; 3301 library dart.core;
3159 const override = null; 3302 const override = null;
3160 class A { 3303 class A {
3161 } 3304 }
3162 class B extends A { 3305 class B extends A {
3163 @override 3306 @override
3164 int get m => 1; 3307 int get m => 1;
3165 }'''); 3308 }''');
(...skipping 3727 matching lines...) Expand 10 before | Expand all | Expand 10 after
6893 verify([source]); 7036 verify([source]);
6894 } 7037 }
6895 7038
6896 void test_missingReturn_voidReturnType() { 7039 void test_missingReturn_voidReturnType() {
6897 Source source = addSource("void f() {}"); 7040 Source source = addSource("void f() {}");
6898 computeLibrarySourceErrors(source); 7041 computeLibrarySourceErrors(source);
6899 assertNoErrors(source); 7042 assertNoErrors(source);
6900 verify([source]); 7043 verify([source]);
6901 } 7044 }
6902 7045
7046 void test_nullAwareInCondition_for_noCondition() {
7047 Source source = addSource(r'''
7048 m(x) {
7049 for (var v = x; ; v++) {}
7050 }
7051 ''');
7052 computeLibrarySourceErrors(source);
7053 assertNoErrors(source);
7054 verify([source]);
7055 }
7056
7057 void test_nullAwareInCondition_if_notTopLevel() {
7058 Source source = addSource(r'''
7059 m(x) {
7060 if (x?.y == null) {}
7061 }
7062 ''');
7063 computeLibrarySourceErrors(source);
7064 assertNoErrors(source);
7065 verify([source]);
7066 }
7067
6903 void test_overrideEqualsButNotHashCode() { 7068 void test_overrideEqualsButNotHashCode() {
6904 Source source = addSource(r''' 7069 Source source = addSource(r'''
6905 class A { 7070 class A {
6906 bool operator ==(x) { return x; } 7071 bool operator ==(x) { return x; }
6907 get hashCode => 0; 7072 get hashCode => 0;
6908 }'''); 7073 }''');
6909 computeLibrarySourceErrors(source); 7074 computeLibrarySourceErrors(source);
6910 assertNoErrors(source); 7075 assertNoErrors(source);
6911 verify([source]); 7076 verify([source]);
6912 } 7077 }
(...skipping 7940 matching lines...) Expand 10 before | Expand all | Expand 10 after
14853 15018
14854 void _resolveTestUnit(String code) { 15019 void _resolveTestUnit(String code) {
14855 testCode = code; 15020 testCode = code;
14856 testSource = addSource(testCode); 15021 testSource = addSource(testCode);
14857 LibraryElement library = resolve2(testSource); 15022 LibraryElement library = resolve2(testSource);
14858 assertNoErrors(testSource); 15023 assertNoErrors(testSource);
14859 verify([testSource]); 15024 verify([testSource]);
14860 testUnit = resolveCompilationUnit(testSource, library); 15025 testUnit = resolveCompilationUnit(testSource, library);
14861 } 15026 }
14862 } 15027 }
OLDNEW
« 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