| OLD | NEW |
| 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.static_warning_code_test; | 5 library engine.static_warning_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/source_io.dart'; | 8 import 'package:analyzer/src/generated/source_io.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 HintCode.UNUSED_IMPORT]); | 1400 HintCode.UNUSED_IMPORT]); |
| 1401 verify([source]); | 1401 verify([source]); |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 void test_importOfNonLibrary() { | 1404 void test_importOfNonLibrary() { |
| 1405 resolveWithErrors(<String>[r''' | 1405 resolveWithErrors(<String>[r''' |
| 1406 part of lib; | 1406 part of lib; |
| 1407 class A {}''', r''' | 1407 class A {}''', r''' |
| 1408 library lib; | 1408 library lib; |
| 1409 import 'lib1.dart' deferred as p; | 1409 import 'lib1.dart' deferred as p; |
| 1410 var a = new p.A();'''], | 1410 var a = new p.A();'''], <ErrorCode>[StaticWarningCode.IMPORT_OF_NON_LIBRARY]); |
| 1411 <ErrorCode>[StaticWarningCode.IMPORT_OF_NON_LIBRARY]); | |
| 1412 } | 1411 } |
| 1413 | 1412 |
| 1414 void test_inconsistentMethodInheritanceGetterAndMethod() { | 1413 void test_inconsistentMethodInheritanceGetterAndMethod() { |
| 1415 Source source = addSource(r''' | 1414 Source source = addSource(r''' |
| 1416 abstract class A { | 1415 abstract class A { |
| 1417 int x(); | 1416 int x(); |
| 1418 } | 1417 } |
| 1419 abstract class B { | 1418 abstract class B { |
| 1420 int get x; | 1419 int get x; |
| 1421 } | 1420 } |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2938 void test_redirectToNonClass_undefinedIdentifier() { | 2937 void test_redirectToNonClass_undefinedIdentifier() { |
| 2939 Source source = addSource(r''' | 2938 Source source = addSource(r''' |
| 2940 class B { | 2939 class B { |
| 2941 factory B() = A; | 2940 factory B() = A; |
| 2942 }'''); | 2941 }'''); |
| 2943 resolve(source); | 2942 resolve(source); |
| 2944 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); | 2943 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); |
| 2945 verify([source]); | 2944 verify([source]); |
| 2946 } | 2945 } |
| 2947 | 2946 |
| 2947 void test_returnWithoutValue_async() { |
| 2948 Source source = addSource(''' |
| 2949 import 'dart:async'; |
| 2950 Future<int> f() async { |
| 2951 return; |
| 2952 } |
| 2953 '''); |
| 2954 resolve(source); |
| 2955 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2956 verify([source]); |
| 2957 } |
| 2958 |
| 2948 void test_returnWithoutValue_factoryConstructor() { | 2959 void test_returnWithoutValue_factoryConstructor() { |
| 2949 Source source = addSource("class A { factory A() { return; } }"); | 2960 Source source = addSource("class A { factory A() { return; } }"); |
| 2950 resolve(source); | 2961 resolve(source); |
| 2951 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); | 2962 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2952 verify([source]); | 2963 verify([source]); |
| 2953 } | 2964 } |
| 2954 | 2965 |
| 2955 void test_returnWithoutValue_function() { | 2966 void test_returnWithoutValue_function() { |
| 2956 Source source = addSource("int f() { return; }"); | 2967 Source source = addSource("int f() { return; }"); |
| 2957 resolve(source); | 2968 resolve(source); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3059 } | 3070 } |
| 3060 | 3071 |
| 3061 void test_typeAnnotationDeferredClass_asExpression() { | 3072 void test_typeAnnotationDeferredClass_asExpression() { |
| 3062 resolveWithErrors(<String>[r''' | 3073 resolveWithErrors(<String>[r''' |
| 3063 library lib1; | 3074 library lib1; |
| 3064 class A {}''', r''' | 3075 class A {}''', r''' |
| 3065 library root; | 3076 library root; |
| 3066 import 'lib1.dart' deferred as a; | 3077 import 'lib1.dart' deferred as a; |
| 3067 f(var v) { | 3078 f(var v) { |
| 3068 v as a.A; | 3079 v as a.A; |
| 3069 }'''], | 3080 }'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3070 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3071 } | 3081 } |
| 3072 | 3082 |
| 3073 void test_typeAnnotationDeferredClass_catchClause() { | 3083 void test_typeAnnotationDeferredClass_catchClause() { |
| 3074 resolveWithErrors(<String>[r''' | 3084 resolveWithErrors(<String>[r''' |
| 3075 library lib1; | 3085 library lib1; |
| 3076 class A {}''', r''' | 3086 class A {}''', r''' |
| 3077 library root; | 3087 library root; |
| 3078 import 'lib1.dart' deferred as a; | 3088 import 'lib1.dart' deferred as a; |
| 3079 f(var v) { | 3089 f(var v) { |
| 3080 try { | 3090 try { |
| 3081 } on a.A { | 3091 } on a.A { |
| 3082 } | 3092 } |
| 3083 }'''], | 3093 }'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3084 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3085 } | 3094 } |
| 3086 | 3095 |
| 3087 void test_typeAnnotationDeferredClass_fieldFormalParameter() { | 3096 void test_typeAnnotationDeferredClass_fieldFormalParameter() { |
| 3088 resolveWithErrors(<String>[r''' | 3097 resolveWithErrors(<String>[r''' |
| 3089 library lib1; | 3098 library lib1; |
| 3090 class A {}''', r''' | 3099 class A {}''', r''' |
| 3091 library root; | 3100 library root; |
| 3092 import 'lib1.dart' deferred as a; | 3101 import 'lib1.dart' deferred as a; |
| 3093 class C { | 3102 class C { |
| 3094 var v; | 3103 var v; |
| 3095 C(a.A this.v); | 3104 C(a.A this.v); |
| 3096 }'''], | 3105 }'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3097 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3098 } | 3106 } |
| 3099 | 3107 |
| 3100 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() { | 3108 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() { |
| 3101 resolveWithErrors(<String>[r''' | 3109 resolveWithErrors(<String>[r''' |
| 3102 library lib1; | 3110 library lib1; |
| 3103 class A {}''', r''' | 3111 class A {}''', r''' |
| 3104 library root; | 3112 library root; |
| 3105 import 'lib1.dart' deferred as a; | 3113 import 'lib1.dart' deferred as a; |
| 3106 a.A f() { return null; }'''], | 3114 a.A f() { return null; }'''], |
| 3107 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3115 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3119 } | 3127 } |
| 3120 | 3128 |
| 3121 void test_typeAnnotationDeferredClass_isExpression() { | 3129 void test_typeAnnotationDeferredClass_isExpression() { |
| 3122 resolveWithErrors(<String>[r''' | 3130 resolveWithErrors(<String>[r''' |
| 3123 library lib1; | 3131 library lib1; |
| 3124 class A {}''', r''' | 3132 class A {}''', r''' |
| 3125 library root; | 3133 library root; |
| 3126 import 'lib1.dart' deferred as a; | 3134 import 'lib1.dart' deferred as a; |
| 3127 f(var v) { | 3135 f(var v) { |
| 3128 bool b = v is a.A; | 3136 bool b = v is a.A; |
| 3129 }'''], | 3137 }'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3130 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3131 } | 3138 } |
| 3132 | 3139 |
| 3133 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() { | 3140 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() { |
| 3134 resolveWithErrors(<String>[r''' | 3141 resolveWithErrors(<String>[r''' |
| 3135 library lib1; | 3142 library lib1; |
| 3136 class A {}''', r''' | 3143 class A {}''', r''' |
| 3137 library root; | 3144 library root; |
| 3138 import 'lib1.dart' deferred as a; | 3145 import 'lib1.dart' deferred as a; |
| 3139 class C { | 3146 class C { |
| 3140 a.A m() { return null; } | 3147 a.A m() { return null; } |
| 3141 }'''], | 3148 }'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3142 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3143 } | 3149 } |
| 3144 | 3150 |
| 3145 void test_typeAnnotationDeferredClass_simpleFormalParameter() { | 3151 void test_typeAnnotationDeferredClass_simpleFormalParameter() { |
| 3146 resolveWithErrors(<String>[r''' | 3152 resolveWithErrors(<String>[r''' |
| 3147 library lib1; | 3153 library lib1; |
| 3148 class A {}''', r''' | 3154 class A {}''', r''' |
| 3149 library root; | 3155 library root; |
| 3150 import 'lib1.dart' deferred as a; | 3156 import 'lib1.dart' deferred as a; |
| 3151 f(a.A v) {}'''], | 3157 f(a.A v) {}'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3152 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3153 } | 3158 } |
| 3154 | 3159 |
| 3155 void test_typeAnnotationDeferredClass_typeArgumentList() { | 3160 void test_typeAnnotationDeferredClass_typeArgumentList() { |
| 3156 resolveWithErrors(<String>[r''' | 3161 resolveWithErrors(<String>[r''' |
| 3157 library lib1; | 3162 library lib1; |
| 3158 class A {}''', r''' | 3163 class A {}''', r''' |
| 3159 library root; | 3164 library root; |
| 3160 import 'lib1.dart' deferred as a; | 3165 import 'lib1.dart' deferred as a; |
| 3161 class C<E> {} | 3166 class C<E> {} |
| 3162 C<a.A> c;'''], | 3167 C<a.A> c;'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3163 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3164 } | 3168 } |
| 3165 | 3169 |
| 3166 void test_typeAnnotationDeferredClass_typeArgumentList2() { | 3170 void test_typeAnnotationDeferredClass_typeArgumentList2() { |
| 3167 resolveWithErrors(<String>[r''' | 3171 resolveWithErrors(<String>[r''' |
| 3168 library lib1; | 3172 library lib1; |
| 3169 class A {}''', r''' | 3173 class A {}''', r''' |
| 3170 library root; | 3174 library root; |
| 3171 import 'lib1.dart' deferred as a; | 3175 import 'lib1.dart' deferred as a; |
| 3172 class C<E, F> {} | 3176 class C<E, F> {} |
| 3173 C<a.A, a.A> c;'''], | 3177 C<a.A, a.A> c;'''], |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3185 class C<E extends a.A> {}'''], | 3189 class C<E extends a.A> {}'''], |
| 3186 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3190 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3187 } | 3191 } |
| 3188 | 3192 |
| 3189 void test_typeAnnotationDeferredClass_variableDeclarationList() { | 3193 void test_typeAnnotationDeferredClass_variableDeclarationList() { |
| 3190 resolveWithErrors(<String>[r''' | 3194 resolveWithErrors(<String>[r''' |
| 3191 library lib1; | 3195 library lib1; |
| 3192 class A {}''', r''' | 3196 class A {}''', r''' |
| 3193 library root; | 3197 library root; |
| 3194 import 'lib1.dart' deferred as a; | 3198 import 'lib1.dart' deferred as a; |
| 3195 a.A v;'''], | 3199 a.A v;'''], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3196 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | |
| 3197 } | 3200 } |
| 3198 | 3201 |
| 3199 void test_typeParameterReferencedByStatic_field() { | 3202 void test_typeParameterReferencedByStatic_field() { |
| 3200 Source source = addSource(r''' | 3203 Source source = addSource(r''' |
| 3201 class A<K> { | 3204 class A<K> { |
| 3202 static K k; | 3205 static K k; |
| 3203 }'''); | 3206 }'''); |
| 3204 resolve(source); | 3207 resolve(source); |
| 3205 assertErrors( | 3208 assertErrors( |
| 3206 source, | 3209 source, |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3512 | 3515 |
| 3513 void test_voidReturnForGetter() { | 3516 void test_voidReturnForGetter() { |
| 3514 Source source = addSource(r''' | 3517 Source source = addSource(r''' |
| 3515 class S { | 3518 class S { |
| 3516 void get value {} | 3519 void get value {} |
| 3517 }'''); | 3520 }'''); |
| 3518 resolve(source); | 3521 resolve(source); |
| 3519 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); | 3522 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); |
| 3520 } | 3523 } |
| 3521 } | 3524 } |
| OLD | NEW |