| 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/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 assertErrors( | 1396 assertErrors( |
| 1397 source, | 1397 source, |
| 1398 [ | 1398 [ |
| 1399 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_UNNAMED, | 1399 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_UNNAMED, |
| 1400 HintCode.UNUSED_IMPORT, | 1400 HintCode.UNUSED_IMPORT, |
| 1401 HintCode.UNUSED_IMPORT]); | 1401 HintCode.UNUSED_IMPORT]); |
| 1402 verify([source]); | 1402 verify([source]); |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 void test_importOfNonLibrary() { | 1405 void test_importOfNonLibrary() { |
| 1406 resolveWithAndWithoutExperimental(<String>[r''' | 1406 resolveWithErrors(<String>[r''' |
| 1407 part of lib; | 1407 part of lib; |
| 1408 class A {}''', r''' | 1408 class A {}''', r''' |
| 1409 library lib; | 1409 library lib; |
| 1410 import 'lib1.dart' deferred as p; | 1410 import 'lib1.dart' deferred as p; |
| 1411 var a = new p.A();'''], | 1411 var a = new p.A();'''], |
| 1412 <ErrorCode>[ | |
| 1413 CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, | |
| 1414 ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 1415 <ErrorCode>[StaticWarningCode.IMPORT_OF_NON_LIBRARY]); | 1412 <ErrorCode>[StaticWarningCode.IMPORT_OF_NON_LIBRARY]); |
| 1416 } | 1413 } |
| 1417 | 1414 |
| 1418 void test_inconsistentMethodInheritanceGetterAndMethod() { | 1415 void test_inconsistentMethodInheritanceGetterAndMethod() { |
| 1419 Source source = addSource(r''' | 1416 Source source = addSource(r''' |
| 1420 abstract class A { | 1417 abstract class A { |
| 1421 int x(); | 1418 int x(); |
| 1422 } | 1419 } |
| 1423 abstract class B { | 1420 abstract class B { |
| 1424 int get x; | 1421 int get x; |
| (...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3056 switch (p) { | 3053 switch (p) { |
| 3057 case 'a': break; | 3054 case 'a': break; |
| 3058 } | 3055 } |
| 3059 }'''); | 3056 }'''); |
| 3060 resolve(source); | 3057 resolve(source); |
| 3061 assertErrors(source, [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]); | 3058 assertErrors(source, [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]); |
| 3062 verify([source]); | 3059 verify([source]); |
| 3063 } | 3060 } |
| 3064 | 3061 |
| 3065 void test_typeAnnotationDeferredClass_asExpression() { | 3062 void test_typeAnnotationDeferredClass_asExpression() { |
| 3066 resolveWithAndWithoutExperimental(<String>[r''' | 3063 resolveWithErrors(<String>[r''' |
| 3067 library lib1; | 3064 library lib1; |
| 3068 class A {}''', r''' | 3065 class A {}''', r''' |
| 3069 library root; | 3066 library root; |
| 3070 import 'lib1.dart' deferred as a; | 3067 import 'lib1.dart' deferred as a; |
| 3071 f(var v) { | 3068 f(var v) { |
| 3072 v as a.A; | 3069 v as a.A; |
| 3073 }'''], | 3070 }'''], |
| 3074 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3075 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3071 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3076 } | 3072 } |
| 3077 | 3073 |
| 3078 void test_typeAnnotationDeferredClass_catchClause() { | 3074 void test_typeAnnotationDeferredClass_catchClause() { |
| 3079 resolveWithAndWithoutExperimental(<String>[r''' | 3075 resolveWithErrors(<String>[r''' |
| 3080 library lib1; | 3076 library lib1; |
| 3081 class A {}''', r''' | 3077 class A {}''', r''' |
| 3082 library root; | 3078 library root; |
| 3083 import 'lib1.dart' deferred as a; | 3079 import 'lib1.dart' deferred as a; |
| 3084 f(var v) { | 3080 f(var v) { |
| 3085 try { | 3081 try { |
| 3086 } on a.A { | 3082 } on a.A { |
| 3087 } | 3083 } |
| 3088 }'''], | 3084 }'''], |
| 3089 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3090 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3085 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3091 } | 3086 } |
| 3092 | 3087 |
| 3093 void test_typeAnnotationDeferredClass_fieldFormalParameter() { | 3088 void test_typeAnnotationDeferredClass_fieldFormalParameter() { |
| 3094 resolveWithAndWithoutExperimental(<String>[r''' | 3089 resolveWithErrors(<String>[r''' |
| 3095 library lib1; | 3090 library lib1; |
| 3096 class A {}''', r''' | 3091 class A {}''', r''' |
| 3097 library root; | 3092 library root; |
| 3098 import 'lib1.dart' deferred as a; | 3093 import 'lib1.dart' deferred as a; |
| 3099 class C { | 3094 class C { |
| 3100 var v; | 3095 var v; |
| 3101 C(a.A this.v); | 3096 C(a.A this.v); |
| 3102 }'''], | 3097 }'''], |
| 3103 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3104 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3098 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3105 } | 3099 } |
| 3106 | 3100 |
| 3107 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() { | 3101 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() { |
| 3108 resolveWithAndWithoutExperimental(<String>[r''' | 3102 resolveWithErrors(<String>[r''' |
| 3109 library lib1; | 3103 library lib1; |
| 3110 class A {}''', r''' | 3104 class A {}''', r''' |
| 3111 library root; | 3105 library root; |
| 3112 import 'lib1.dart' deferred as a; | 3106 import 'lib1.dart' deferred as a; |
| 3113 a.A f() { return null; }'''], | 3107 a.A f() { return null; }'''], |
| 3114 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3115 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3108 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3116 } | 3109 } |
| 3117 | 3110 |
| 3118 void | 3111 void |
| 3119 test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType()
{ | 3112 test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType()
{ |
| 3120 resolveWithAndWithoutExperimental(<String>[r''' | 3113 resolveWithErrors(<String>[r''' |
| 3121 library lib1; | 3114 library lib1; |
| 3122 class A {}''', r''' | 3115 class A {}''', r''' |
| 3123 library root; | 3116 library root; |
| 3124 import 'lib1.dart' deferred as a; | 3117 import 'lib1.dart' deferred as a; |
| 3125 f(a.A g()) {}'''], | 3118 f(a.A g()) {}'''], |
| 3126 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3127 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3119 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3128 } | 3120 } |
| 3129 | 3121 |
| 3130 void test_typeAnnotationDeferredClass_isExpression() { | 3122 void test_typeAnnotationDeferredClass_isExpression() { |
| 3131 resolveWithAndWithoutExperimental(<String>[r''' | 3123 resolveWithErrors(<String>[r''' |
| 3132 library lib1; | 3124 library lib1; |
| 3133 class A {}''', r''' | 3125 class A {}''', r''' |
| 3134 library root; | 3126 library root; |
| 3135 import 'lib1.dart' deferred as a; | 3127 import 'lib1.dart' deferred as a; |
| 3136 f(var v) { | 3128 f(var v) { |
| 3137 bool b = v is a.A; | 3129 bool b = v is a.A; |
| 3138 }'''], | 3130 }'''], |
| 3139 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3140 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3131 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3141 } | 3132 } |
| 3142 | 3133 |
| 3143 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() { | 3134 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() { |
| 3144 resolveWithAndWithoutExperimental(<String>[r''' | 3135 resolveWithErrors(<String>[r''' |
| 3145 library lib1; | 3136 library lib1; |
| 3146 class A {}''', r''' | 3137 class A {}''', r''' |
| 3147 library root; | 3138 library root; |
| 3148 import 'lib1.dart' deferred as a; | 3139 import 'lib1.dart' deferred as a; |
| 3149 class C { | 3140 class C { |
| 3150 a.A m() { return null; } | 3141 a.A m() { return null; } |
| 3151 }'''], | 3142 }'''], |
| 3152 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3153 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3143 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3154 } | 3144 } |
| 3155 | 3145 |
| 3156 void test_typeAnnotationDeferredClass_simpleFormalParameter() { | 3146 void test_typeAnnotationDeferredClass_simpleFormalParameter() { |
| 3157 resolveWithAndWithoutExperimental(<String>[r''' | 3147 resolveWithErrors(<String>[r''' |
| 3158 library lib1; | 3148 library lib1; |
| 3159 class A {}''', r''' | 3149 class A {}''', r''' |
| 3160 library root; | 3150 library root; |
| 3161 import 'lib1.dart' deferred as a; | 3151 import 'lib1.dart' deferred as a; |
| 3162 f(a.A v) {}'''], | 3152 f(a.A v) {}'''], |
| 3163 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3164 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3153 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3165 } | 3154 } |
| 3166 | 3155 |
| 3167 void test_typeAnnotationDeferredClass_typeArgumentList() { | 3156 void test_typeAnnotationDeferredClass_typeArgumentList() { |
| 3168 resolveWithAndWithoutExperimental(<String>[r''' | 3157 resolveWithErrors(<String>[r''' |
| 3169 library lib1; | 3158 library lib1; |
| 3170 class A {}''', r''' | 3159 class A {}''', r''' |
| 3171 library root; | 3160 library root; |
| 3172 import 'lib1.dart' deferred as a; | 3161 import 'lib1.dart' deferred as a; |
| 3173 class C<E> {} | 3162 class C<E> {} |
| 3174 C<a.A> c;'''], | 3163 C<a.A> c;'''], |
| 3175 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3176 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3164 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3177 } | 3165 } |
| 3178 | 3166 |
| 3179 void test_typeAnnotationDeferredClass_typeArgumentList2() { | 3167 void test_typeAnnotationDeferredClass_typeArgumentList2() { |
| 3180 resolveWithAndWithoutExperimental(<String>[r''' | 3168 resolveWithErrors(<String>[r''' |
| 3181 library lib1; | 3169 library lib1; |
| 3182 class A {}''', r''' | 3170 class A {}''', r''' |
| 3183 library root; | 3171 library root; |
| 3184 import 'lib1.dart' deferred as a; | 3172 import 'lib1.dart' deferred as a; |
| 3185 class C<E, F> {} | 3173 class C<E, F> {} |
| 3186 C<a.A, a.A> c;'''], | 3174 C<a.A, a.A> c;'''], |
| 3187 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3188 <ErrorCode>[ | 3175 <ErrorCode>[ |
| 3189 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, | 3176 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, |
| 3190 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3177 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3191 } | 3178 } |
| 3192 | 3179 |
| 3193 void test_typeAnnotationDeferredClass_typeParameter_bound() { | 3180 void test_typeAnnotationDeferredClass_typeParameter_bound() { |
| 3194 resolveWithAndWithoutExperimental(<String>[r''' | 3181 resolveWithErrors(<String>[r''' |
| 3195 library lib1; | 3182 library lib1; |
| 3196 class A {}''', r''' | 3183 class A {}''', r''' |
| 3197 library root; | 3184 library root; |
| 3198 import 'lib1.dart' deferred as a; | 3185 import 'lib1.dart' deferred as a; |
| 3199 class C<E extends a.A> {}'''], | 3186 class C<E extends a.A> {}'''], |
| 3200 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3201 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3187 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3202 } | 3188 } |
| 3203 | 3189 |
| 3204 void test_typeAnnotationDeferredClass_variableDeclarationList() { | 3190 void test_typeAnnotationDeferredClass_variableDeclarationList() { |
| 3205 resolveWithAndWithoutExperimental(<String>[r''' | 3191 resolveWithErrors(<String>[r''' |
| 3206 library lib1; | 3192 library lib1; |
| 3207 class A {}''', r''' | 3193 class A {}''', r''' |
| 3208 library root; | 3194 library root; |
| 3209 import 'lib1.dart' deferred as a; | 3195 import 'lib1.dart' deferred as a; |
| 3210 a.A v;'''], | 3196 a.A v;'''], |
| 3211 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], | |
| 3212 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); | 3197 <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); |
| 3213 } | 3198 } |
| 3214 | 3199 |
| 3215 void test_typeParameterReferencedByStatic_field() { | 3200 void test_typeParameterReferencedByStatic_field() { |
| 3216 Source source = addSource(r''' | 3201 Source source = addSource(r''' |
| 3217 class A<K> { | 3202 class A<K> { |
| 3218 static K k; | 3203 static K k; |
| 3219 }'''); | 3204 }'''); |
| 3220 resolve(source); | 3205 resolve(source); |
| 3221 assertErrors( | 3206 assertErrors( |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3528 | 3513 |
| 3529 void test_voidReturnForGetter() { | 3514 void test_voidReturnForGetter() { |
| 3530 Source source = addSource(r''' | 3515 Source source = addSource(r''' |
| 3531 class S { | 3516 class S { |
| 3532 void get value {} | 3517 void get value {} |
| 3533 }'''); | 3518 }'''); |
| 3534 resolve(source); | 3519 resolve(source); |
| 3535 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); | 3520 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); |
| 3536 } | 3521 } |
| 3537 } | 3522 } |
| OLD | NEW |