| 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 analyzer.test.generated.static_warning_code_test; | 5 library analyzer.test.generated.static_warning_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
| 8 import 'package:analyzer/src/error/codes.dart'; | 8 import 'package:analyzer/src/error/codes.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source_io.dart'; | 10 import 'package:analyzer/src/generated/source_io.dart'; |
| 11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 | 13 |
| 14 import 'resolver_test_case.dart'; | 14 import 'resolver_test_case.dart'; |
| 15 | 15 |
| 16 main() { | 16 main() { |
| 17 defineReflectiveSuite(() { | 17 defineReflectiveSuite(() { |
| 18 defineReflectiveTests(StaticWarningCodeTest); | 18 defineReflectiveTests(StaticWarningCodeTest); |
| 19 }); | 19 }); |
| 20 } | 20 } |
| 21 | 21 |
| 22 @reflectiveTest | 22 @reflectiveTest |
| 23 class StaticWarningCodeTest extends ResolverTestCase { | 23 class StaticWarningCodeTest extends ResolverTestCase { |
| 24 void fail_argumentTypeNotAssignable_tearOff_required() { | 24 fail_argumentTypeNotAssignable_tearOff_required() async { |
| 25 Source source = addSource(r''' | 25 Source source = addSource(r''' |
| 26 class C { | 26 class C { |
| 27 Object/*=T*/ f/*<T>*/(Object/*=T*/ x) => x; | 27 Object/*=T*/ f/*<T>*/(Object/*=T*/ x) => x; |
| 28 } | 28 } |
| 29 g(C c) { | 29 g(C c) { |
| 30 var h = c.f/*<int>*/; | 30 var h = c.f/*<int>*/; |
| 31 print(h('s')); | 31 print(h('s')); |
| 32 } | 32 } |
| 33 '''); | 33 '''); |
| 34 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 34 await assertErrors( |
| 35 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 35 verify([source]); | 36 verify([source]); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void fail_undefinedGetter() { | 39 fail_undefinedGetter() async { |
| 39 Source source = addSource(r''' | 40 Source source = addSource(r''' |
| 40 '''); | 41 '''); |
| 41 assertErrors(source, [StaticWarningCode.UNDEFINED_GETTER]); | 42 await assertErrors(source, [StaticWarningCode.UNDEFINED_GETTER]); |
| 42 verify([source]); | 43 verify([source]); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void fail_undefinedIdentifier_commentReference() { | 46 fail_undefinedIdentifier_commentReference() async { |
| 46 Source source = addSource(r''' | 47 Source source = addSource(r''' |
| 47 /** [m] xxx [new B.c] */ | 48 /** [m] xxx [new B.c] */ |
| 48 class A { | 49 class A { |
| 49 }'''); | 50 }'''); |
| 50 assertErrors(source, [ | 51 await assertErrors(source, [ |
| 51 StaticWarningCode.UNDEFINED_IDENTIFIER, | 52 StaticWarningCode.UNDEFINED_IDENTIFIER, |
| 52 StaticWarningCode.UNDEFINED_IDENTIFIER | 53 StaticWarningCode.UNDEFINED_IDENTIFIER |
| 53 ]); | 54 ]); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void fail_undefinedSetter() { | 57 fail_undefinedSetter() async { |
| 57 Source source = addSource(r''' | 58 Source source = addSource(r''' |
| 58 class C {} | 59 class C {} |
| 59 f(var p) { | 60 f(var p) { |
| 60 C.m = 0; | 61 C.m = 0; |
| 61 }'''); | 62 }'''); |
| 62 assertErrors(source, [StaticWarningCode.UNDEFINED_SETTER]); | 63 await assertErrors(source, [StaticWarningCode.UNDEFINED_SETTER]); |
| 63 verify([source]); | 64 verify([source]); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void test_ambiguousImport_as() { | 67 test_ambiguousImport_as() async { |
| 67 Source source = addSource(r''' | 68 Source source = addSource(r''' |
| 68 import 'lib1.dart'; | 69 import 'lib1.dart'; |
| 69 import 'lib2.dart'; | 70 import 'lib2.dart'; |
| 70 f(p) {p as N;}'''); | 71 f(p) {p as N;}'''); |
| 71 addNamedSource( | 72 addNamedSource( |
| 72 "/lib1.dart", | 73 "/lib1.dart", |
| 73 r''' | 74 r''' |
| 74 library lib1; | 75 library lib1; |
| 75 class N {}'''); | 76 class N {}'''); |
| 76 addNamedSource( | 77 addNamedSource( |
| 77 "/lib2.dart", | 78 "/lib2.dart", |
| 78 r''' | 79 r''' |
| 79 library lib2; | 80 library lib2; |
| 80 class N {}'''); | 81 class N {}'''); |
| 81 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 82 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void test_ambiguousImport_extends() { | 85 test_ambiguousImport_extends() async { |
| 85 Source source = addSource(r''' | 86 Source source = addSource(r''' |
| 86 import 'lib1.dart'; | 87 import 'lib1.dart'; |
| 87 import 'lib2.dart'; | 88 import 'lib2.dart'; |
| 88 class A extends N {}'''); | 89 class A extends N {}'''); |
| 89 addNamedSource( | 90 addNamedSource( |
| 90 "/lib1.dart", | 91 "/lib1.dart", |
| 91 r''' | 92 r''' |
| 92 library lib1; | 93 library lib1; |
| 93 class N {}'''); | 94 class N {}'''); |
| 94 addNamedSource( | 95 addNamedSource( |
| 95 "/lib2.dart", | 96 "/lib2.dart", |
| 96 r''' | 97 r''' |
| 97 library lib2; | 98 library lib2; |
| 98 class N {}'''); | 99 class N {}'''); |
| 99 assertErrors(source, [ | 100 await assertErrors(source, [ |
| 100 StaticWarningCode.AMBIGUOUS_IMPORT, | 101 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 101 CompileTimeErrorCode.EXTENDS_NON_CLASS | 102 CompileTimeErrorCode.EXTENDS_NON_CLASS |
| 102 ]); | 103 ]); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void test_ambiguousImport_implements() { | 106 test_ambiguousImport_implements() async { |
| 106 Source source = addSource(r''' | 107 Source source = addSource(r''' |
| 107 import 'lib1.dart'; | 108 import 'lib1.dart'; |
| 108 import 'lib2.dart'; | 109 import 'lib2.dart'; |
| 109 class A implements N {}'''); | 110 class A implements N {}'''); |
| 110 addNamedSource( | 111 addNamedSource( |
| 111 "/lib1.dart", | 112 "/lib1.dart", |
| 112 r''' | 113 r''' |
| 113 library lib1; | 114 library lib1; |
| 114 class N {}'''); | 115 class N {}'''); |
| 115 addNamedSource( | 116 addNamedSource( |
| 116 "/lib2.dart", | 117 "/lib2.dart", |
| 117 r''' | 118 r''' |
| 118 library lib2; | 119 library lib2; |
| 119 class N {}'''); | 120 class N {}'''); |
| 120 assertErrors(source, [ | 121 await assertErrors(source, [ |
| 121 StaticWarningCode.AMBIGUOUS_IMPORT, | 122 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 122 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS | 123 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS |
| 123 ]); | 124 ]); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void test_ambiguousImport_inPart() { | 127 test_ambiguousImport_inPart() async { |
| 127 Source source = addSource(r''' | 128 Source source = addSource(r''' |
| 128 library lib; | 129 library lib; |
| 129 import 'lib1.dart'; | 130 import 'lib1.dart'; |
| 130 import 'lib2.dart'; | 131 import 'lib2.dart'; |
| 131 part 'part.dart';'''); | 132 part 'part.dart';'''); |
| 132 addNamedSource( | 133 addNamedSource( |
| 133 "/lib1.dart", | 134 "/lib1.dart", |
| 134 r''' | 135 r''' |
| 135 library lib1; | 136 library lib1; |
| 136 class N {}'''); | 137 class N {}'''); |
| 137 addNamedSource( | 138 addNamedSource( |
| 138 "/lib2.dart", | 139 "/lib2.dart", |
| 139 r''' | 140 r''' |
| 140 library lib2; | 141 library lib2; |
| 141 class N {}'''); | 142 class N {}'''); |
| 142 Source partSource = addNamedSource( | 143 Source partSource = addNamedSource( |
| 143 "/part.dart", | 144 "/part.dart", |
| 144 r''' | 145 r''' |
| 145 part of lib; | 146 part of lib; |
| 146 class A extends N {}'''); | 147 class A extends N {}'''); |
| 147 assertNoErrors(source); | 148 await assertNoErrors(source); |
| 148 assertErrors(partSource, [ | 149 await assertErrors(partSource, [ |
| 149 StaticWarningCode.AMBIGUOUS_IMPORT, | 150 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 150 CompileTimeErrorCode.EXTENDS_NON_CLASS | 151 CompileTimeErrorCode.EXTENDS_NON_CLASS |
| 151 ]); | 152 ]); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void test_ambiguousImport_instanceCreation() { | 155 test_ambiguousImport_instanceCreation() async { |
| 155 Source source = addSource(r''' | 156 Source source = addSource(r''' |
| 156 library L; | 157 library L; |
| 157 import 'lib1.dart'; | 158 import 'lib1.dart'; |
| 158 import 'lib2.dart'; | 159 import 'lib2.dart'; |
| 159 f() {new N();}'''); | 160 f() {new N();}'''); |
| 160 addNamedSource( | 161 addNamedSource( |
| 161 "/lib1.dart", | 162 "/lib1.dart", |
| 162 r''' | 163 r''' |
| 163 library lib1; | 164 library lib1; |
| 164 class N {}'''); | 165 class N {}'''); |
| 165 addNamedSource( | 166 addNamedSource( |
| 166 "/lib2.dart", | 167 "/lib2.dart", |
| 167 r''' | 168 r''' |
| 168 library lib2; | 169 library lib2; |
| 169 class N {}'''); | 170 class N {}'''); |
| 170 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 171 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void test_ambiguousImport_is() { | 174 test_ambiguousImport_is() async { |
| 174 Source source = addSource(r''' | 175 Source source = addSource(r''' |
| 175 import 'lib1.dart'; | 176 import 'lib1.dart'; |
| 176 import 'lib2.dart'; | 177 import 'lib2.dart'; |
| 177 f(p) {p is N;}'''); | 178 f(p) {p is N;}'''); |
| 178 addNamedSource( | 179 addNamedSource( |
| 179 "/lib1.dart", | 180 "/lib1.dart", |
| 180 r''' | 181 r''' |
| 181 library lib1; | 182 library lib1; |
| 182 class N {}'''); | 183 class N {}'''); |
| 183 addNamedSource( | 184 addNamedSource( |
| 184 "/lib2.dart", | 185 "/lib2.dart", |
| 185 r''' | 186 r''' |
| 186 library lib2; | 187 library lib2; |
| 187 class N {}'''); | 188 class N {}'''); |
| 188 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 189 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void test_ambiguousImport_qualifier() { | 192 test_ambiguousImport_qualifier() async { |
| 192 Source source = addSource(r''' | 193 Source source = addSource(r''' |
| 193 import 'lib1.dart'; | 194 import 'lib1.dart'; |
| 194 import 'lib2.dart'; | 195 import 'lib2.dart'; |
| 195 g() { N.FOO; }'''); | 196 g() { N.FOO; }'''); |
| 196 addNamedSource( | 197 addNamedSource( |
| 197 "/lib1.dart", | 198 "/lib1.dart", |
| 198 r''' | 199 r''' |
| 199 library lib1; | 200 library lib1; |
| 200 class N {}'''); | 201 class N {}'''); |
| 201 addNamedSource( | 202 addNamedSource( |
| 202 "/lib2.dart", | 203 "/lib2.dart", |
| 203 r''' | 204 r''' |
| 204 library lib2; | 205 library lib2; |
| 205 class N {}'''); | 206 class N {}'''); |
| 206 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 207 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void test_ambiguousImport_typeAnnotation() { | 210 test_ambiguousImport_typeAnnotation() async { |
| 210 Source source = addSource(r''' | 211 Source source = addSource(r''' |
| 211 import 'lib1.dart'; | 212 import 'lib1.dart'; |
| 212 import 'lib2.dart'; | 213 import 'lib2.dart'; |
| 213 typedef N FT(N p); | 214 typedef N FT(N p); |
| 214 N f(N p) { | 215 N f(N p) { |
| 215 N v; | 216 N v; |
| 216 return null; | 217 return null; |
| 217 } | 218 } |
| 218 class A { | 219 class A { |
| 219 N m() { return null; } | 220 N m() { return null; } |
| 220 } | 221 } |
| 221 class B<T extends N> {}'''); | 222 class B<T extends N> {}'''); |
| 222 addNamedSource( | 223 addNamedSource( |
| 223 "/lib1.dart", | 224 "/lib1.dart", |
| 224 r''' | 225 r''' |
| 225 library lib1; | 226 library lib1; |
| 226 class N {}'''); | 227 class N {}'''); |
| 227 addNamedSource( | 228 addNamedSource( |
| 228 "/lib2.dart", | 229 "/lib2.dart", |
| 229 r''' | 230 r''' |
| 230 library lib2; | 231 library lib2; |
| 231 class N {}'''); | 232 class N {}'''); |
| 232 assertErrors(source, [ | 233 await assertErrors(source, [ |
| 233 StaticWarningCode.AMBIGUOUS_IMPORT, | 234 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 234 StaticWarningCode.AMBIGUOUS_IMPORT, | 235 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 235 StaticWarningCode.AMBIGUOUS_IMPORT, | 236 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 236 StaticWarningCode.AMBIGUOUS_IMPORT, | 237 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 237 StaticWarningCode.AMBIGUOUS_IMPORT, | 238 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 238 StaticWarningCode.AMBIGUOUS_IMPORT, | 239 StaticWarningCode.AMBIGUOUS_IMPORT, |
| 239 StaticWarningCode.AMBIGUOUS_IMPORT | 240 StaticWarningCode.AMBIGUOUS_IMPORT |
| 240 ]); | 241 ]); |
| 241 } | 242 } |
| 242 | 243 |
| 243 void test_ambiguousImport_typeArgument_annotation() { | 244 test_ambiguousImport_typeArgument_annotation() async { |
| 244 Source source = addSource(r''' | 245 Source source = addSource(r''' |
| 245 import 'lib1.dart'; | 246 import 'lib1.dart'; |
| 246 import 'lib2.dart'; | 247 import 'lib2.dart'; |
| 247 class A<T> {} | 248 class A<T> {} |
| 248 A<N> f() { return null; }'''); | 249 A<N> f() { return null; }'''); |
| 249 addNamedSource( | 250 addNamedSource( |
| 250 "/lib1.dart", | 251 "/lib1.dart", |
| 251 r''' | 252 r''' |
| 252 library lib1; | 253 library lib1; |
| 253 class N {}'''); | 254 class N {}'''); |
| 254 addNamedSource( | 255 addNamedSource( |
| 255 "/lib2.dart", | 256 "/lib2.dart", |
| 256 r''' | 257 r''' |
| 257 library lib2; | 258 library lib2; |
| 258 class N {}'''); | 259 class N {}'''); |
| 259 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 260 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void test_ambiguousImport_typeArgument_instanceCreation() { | 263 test_ambiguousImport_typeArgument_instanceCreation() async { |
| 263 Source source = addSource(r''' | 264 Source source = addSource(r''' |
| 264 import 'lib1.dart'; | 265 import 'lib1.dart'; |
| 265 import 'lib2.dart'; | 266 import 'lib2.dart'; |
| 266 class A<T> {} | 267 class A<T> {} |
| 267 f() {new A<N>();}'''); | 268 f() {new A<N>();}'''); |
| 268 addNamedSource( | 269 addNamedSource( |
| 269 "/lib1.dart", | 270 "/lib1.dart", |
| 270 r''' | 271 r''' |
| 271 library lib1; | 272 library lib1; |
| 272 class N {}'''); | 273 class N {}'''); |
| 273 addNamedSource( | 274 addNamedSource( |
| 274 "/lib2.dart", | 275 "/lib2.dart", |
| 275 r''' | 276 r''' |
| 276 library lib2; | 277 library lib2; |
| 277 class N {}'''); | 278 class N {}'''); |
| 278 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 279 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 279 } | 280 } |
| 280 | 281 |
| 281 void test_ambiguousImport_varRead() { | 282 test_ambiguousImport_varRead() async { |
| 282 Source source = addSource(r''' | 283 Source source = addSource(r''' |
| 283 import 'lib1.dart'; | 284 import 'lib1.dart'; |
| 284 import 'lib2.dart'; | 285 import 'lib2.dart'; |
| 285 f() { g(v); } | 286 f() { g(v); } |
| 286 g(p) {}'''); | 287 g(p) {}'''); |
| 287 addNamedSource( | 288 addNamedSource( |
| 288 "/lib1.dart", | 289 "/lib1.dart", |
| 289 r''' | 290 r''' |
| 290 library lib1; | 291 library lib1; |
| 291 var v;'''); | 292 var v;'''); |
| 292 addNamedSource( | 293 addNamedSource( |
| 293 "/lib2.dart", | 294 "/lib2.dart", |
| 294 r''' | 295 r''' |
| 295 library lib2; | 296 library lib2; |
| 296 var v;'''); | 297 var v;'''); |
| 297 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 298 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 298 } | 299 } |
| 299 | 300 |
| 300 void test_ambiguousImport_varWrite() { | 301 test_ambiguousImport_varWrite() async { |
| 301 Source source = addSource(r''' | 302 Source source = addSource(r''' |
| 302 import 'lib1.dart'; | 303 import 'lib1.dart'; |
| 303 import 'lib2.dart'; | 304 import 'lib2.dart'; |
| 304 f() { v = 0; }'''); | 305 f() { v = 0; }'''); |
| 305 addNamedSource( | 306 addNamedSource( |
| 306 "/lib1.dart", | 307 "/lib1.dart", |
| 307 r''' | 308 r''' |
| 308 library lib1; | 309 library lib1; |
| 309 var v;'''); | 310 var v;'''); |
| 310 addNamedSource( | 311 addNamedSource( |
| 311 "/lib2.dart", | 312 "/lib2.dart", |
| 312 r''' | 313 r''' |
| 313 library lib2; | 314 library lib2; |
| 314 var v;'''); | 315 var v;'''); |
| 315 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 316 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 316 } | 317 } |
| 317 | 318 |
| 318 void test_ambiguousImport_withPrefix() { | 319 test_ambiguousImport_withPrefix() async { |
| 319 Source source = addSource(r''' | 320 Source source = addSource(r''' |
| 320 library test; | 321 library test; |
| 321 import 'lib1.dart' as p; | 322 import 'lib1.dart' as p; |
| 322 import 'lib2.dart' as p; | 323 import 'lib2.dart' as p; |
| 323 main() { | 324 main() { |
| 324 p.f(); | 325 p.f(); |
| 325 }'''); | 326 }'''); |
| 326 addNamedSource( | 327 addNamedSource( |
| 327 "/lib1.dart", | 328 "/lib1.dart", |
| 328 r''' | 329 r''' |
| 329 library lib1; | 330 library lib1; |
| 330 f() {}'''); | 331 f() {}'''); |
| 331 addNamedSource( | 332 addNamedSource( |
| 332 "/lib2.dart", | 333 "/lib2.dart", |
| 333 r''' | 334 r''' |
| 334 library lib2; | 335 library lib2; |
| 335 f() {}'''); | 336 f() {}'''); |
| 336 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 337 await assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 337 } | 338 } |
| 338 | 339 |
| 339 void test_argumentTypeNotAssignable_ambiguousClassName() { | 340 test_argumentTypeNotAssignable_ambiguousClassName() async { |
| 340 // See dartbug.com/19624 | 341 // See dartbug.com/19624 |
| 341 Source source = addNamedSource( | 342 Source source = addNamedSource( |
| 342 "/lib1.dart", | 343 "/lib1.dart", |
| 343 r''' | 344 r''' |
| 344 library lib1; | 345 library lib1; |
| 345 import 'lib2.dart'; | 346 import 'lib2.dart'; |
| 346 class _A {} | 347 class _A {} |
| 347 f() { | 348 f() { |
| 348 g((_A a) {}); | 349 g((_A a) {}); |
| 349 }'''); | 350 }'''); |
| 350 addNamedSource( | 351 addNamedSource( |
| 351 "/lib2.dart", | 352 "/lib2.dart", |
| 352 r''' | 353 r''' |
| 353 library lib2; | 354 library lib2; |
| 354 class _A {} | 355 class _A {} |
| 355 g(h(_A a)) {}'''); | 356 g(h(_A a)) {}'''); |
| 356 // The name _A is private to the library it's defined in, so this is a type | 357 // The name _A is private to the library it's defined in, so this is a type |
| 357 // mismatch. Furthermore, the error message should mention both _A and the | 358 // mismatch. Furthermore, the error message should mention both _A and the |
| 358 // filenames so the user can figure out what's going on. | 359 // filenames so the user can figure out what's going on. |
| 359 List<AnalysisError> errors = analysisContext2.computeErrors(source); | 360 List<AnalysisError> errors = analysisContext2.computeErrors(source); |
| 360 expect(errors, hasLength(1)); | 361 expect(errors, hasLength(1)); |
| 361 AnalysisError error = errors[0]; | 362 AnalysisError error = errors[0]; |
| 362 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, error.errorCode); | 363 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, error.errorCode); |
| 363 String message = error.message; | 364 String message = error.message; |
| 364 expect(message.indexOf("_A") != -1, isTrue); | 365 expect(message.indexOf("_A") != -1, isTrue); |
| 365 expect(message.indexOf("lib1.dart") != -1, isTrue); | 366 expect(message.indexOf("lib1.dart") != -1, isTrue); |
| 366 expect(message.indexOf("lib2.dart") != -1, isTrue); | 367 expect(message.indexOf("lib2.dart") != -1, isTrue); |
| 367 } | 368 } |
| 368 | 369 |
| 369 void test_argumentTypeNotAssignable_annotation_namedConstructor() { | 370 test_argumentTypeNotAssignable_annotation_namedConstructor() async { |
| 370 Source source = addSource(r''' | 371 Source source = addSource(r''' |
| 371 class A { | 372 class A { |
| 372 const A.fromInt(int p); | 373 const A.fromInt(int p); |
| 373 } | 374 } |
| 374 @A.fromInt('0') | 375 @A.fromInt('0') |
| 375 main() { | 376 main() { |
| 376 }'''); | 377 }'''); |
| 377 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 378 await assertErrors( |
| 379 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 378 verify([source]); | 380 verify([source]); |
| 379 } | 381 } |
| 380 | 382 |
| 381 void test_argumentTypeNotAssignable_annotation_unnamedConstructor() { | 383 test_argumentTypeNotAssignable_annotation_unnamedConstructor() async { |
| 382 Source source = addSource(r''' | 384 Source source = addSource(r''' |
| 383 class A { | 385 class A { |
| 384 const A(int p); | 386 const A(int p); |
| 385 } | 387 } |
| 386 @A('0') | 388 @A('0') |
| 387 main() { | 389 main() { |
| 388 }'''); | 390 }'''); |
| 389 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 391 await assertErrors( |
| 392 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 390 verify([source]); | 393 verify([source]); |
| 391 } | 394 } |
| 392 | 395 |
| 393 void test_argumentTypeNotAssignable_binary() { | 396 test_argumentTypeNotAssignable_binary() async { |
| 394 Source source = addSource(r''' | 397 Source source = addSource(r''' |
| 395 class A { | 398 class A { |
| 396 operator +(int p) {} | 399 operator +(int p) {} |
| 397 } | 400 } |
| 398 f(A a) { | 401 f(A a) { |
| 399 a + '0'; | 402 a + '0'; |
| 400 }'''); | 403 }'''); |
| 401 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 404 await assertErrors( |
| 405 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 402 verify([source]); | 406 verify([source]); |
| 403 } | 407 } |
| 404 | 408 |
| 405 void test_argumentTypeNotAssignable_cascadeSecond() { | 409 test_argumentTypeNotAssignable_cascadeSecond() async { |
| 406 Source source = addSource(r''' | 410 Source source = addSource(r''' |
| 407 // filler filler filler filler filler filler filler filler filler filler | 411 // filler filler filler filler filler filler filler filler filler filler |
| 408 class A { | 412 class A { |
| 409 B ma() { return new B(); } | 413 B ma() { return new B(); } |
| 410 } | 414 } |
| 411 class B { | 415 class B { |
| 412 mb(String p) {} | 416 mb(String p) {} |
| 413 } | 417 } |
| 414 | 418 |
| 415 main() { | 419 main() { |
| 416 A a = new A(); | 420 A a = new A(); |
| 417 a.. ma().mb(0); | 421 a.. ma().mb(0); |
| 418 }'''); | 422 }'''); |
| 419 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 423 await assertErrors( |
| 424 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 420 verify([source]); | 425 verify([source]); |
| 421 } | 426 } |
| 422 | 427 |
| 423 void test_argumentTypeNotAssignable_const() { | 428 test_argumentTypeNotAssignable_const() async { |
| 424 Source source = addSource(r''' | 429 Source source = addSource(r''' |
| 425 class A { | 430 class A { |
| 426 const A(String p); | 431 const A(String p); |
| 427 } | 432 } |
| 428 main() { | 433 main() { |
| 429 const A(42); | 434 const A(42); |
| 430 }'''); | 435 }'''); |
| 431 assertErrors(source, [ | 436 await assertErrors(source, [ |
| 432 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 437 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
| 433 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 438 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 434 ]); | 439 ]); |
| 435 verify([source]); | 440 verify([source]); |
| 436 } | 441 } |
| 437 | 442 |
| 438 void test_argumentTypeNotAssignable_const_super() { | 443 test_argumentTypeNotAssignable_const_super() async { |
| 439 Source source = addSource(r''' | 444 Source source = addSource(r''' |
| 440 class A { | 445 class A { |
| 441 const A(String p); | 446 const A(String p); |
| 442 } | 447 } |
| 443 class B extends A { | 448 class B extends A { |
| 444 const B() : super(42); | 449 const B() : super(42); |
| 445 }'''); | 450 }'''); |
| 446 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 451 await assertErrors( |
| 452 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 447 verify([source]); | 453 verify([source]); |
| 448 } | 454 } |
| 449 | 455 |
| 450 void test_argumentTypeNotAssignable_functionExpressionInvocation_required() { | 456 test_argumentTypeNotAssignable_functionExpressionInvocation_required() async { |
| 451 Source source = addSource(r''' | 457 Source source = addSource(r''' |
| 452 main() { | 458 main() { |
| 453 (int x) {} (''); | 459 (int x) {} (''); |
| 454 }'''); | 460 }'''); |
| 455 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 461 await assertErrors( |
| 462 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 456 verify([source]); | 463 verify([source]); |
| 457 } | 464 } |
| 458 | 465 |
| 459 void test_argumentTypeNotAssignable_index() { | 466 test_argumentTypeNotAssignable_index() async { |
| 460 Source source = addSource(r''' | 467 Source source = addSource(r''' |
| 461 class A { | 468 class A { |
| 462 operator [](int index) {} | 469 operator [](int index) {} |
| 463 } | 470 } |
| 464 f(A a) { | 471 f(A a) { |
| 465 a['0']; | 472 a['0']; |
| 466 }'''); | 473 }'''); |
| 467 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 474 await assertErrors( |
| 475 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 468 verify([source]); | 476 verify([source]); |
| 469 } | 477 } |
| 470 | 478 |
| 471 void test_argumentTypeNotAssignable_invocation_callParameter() { | 479 test_argumentTypeNotAssignable_invocation_callParameter() async { |
| 472 Source source = addSource(r''' | 480 Source source = addSource(r''' |
| 473 class A { | 481 class A { |
| 474 call(int p) {} | 482 call(int p) {} |
| 475 } | 483 } |
| 476 f(A a) { | 484 f(A a) { |
| 477 a('0'); | 485 a('0'); |
| 478 }'''); | 486 }'''); |
| 479 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 487 await assertErrors( |
| 488 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 480 verify([source]); | 489 verify([source]); |
| 481 } | 490 } |
| 482 | 491 |
| 483 void test_argumentTypeNotAssignable_invocation_callVariable() { | 492 test_argumentTypeNotAssignable_invocation_callVariable() async { |
| 484 Source source = addSource(r''' | 493 Source source = addSource(r''' |
| 485 class A { | 494 class A { |
| 486 call(int p) {} | 495 call(int p) {} |
| 487 } | 496 } |
| 488 main() { | 497 main() { |
| 489 A a = new A(); | 498 A a = new A(); |
| 490 a('0'); | 499 a('0'); |
| 491 }'''); | 500 }'''); |
| 492 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 501 await assertErrors( |
| 502 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 493 verify([source]); | 503 verify([source]); |
| 494 } | 504 } |
| 495 | 505 |
| 496 void test_argumentTypeNotAssignable_invocation_functionParameter() { | 506 test_argumentTypeNotAssignable_invocation_functionParameter() async { |
| 497 Source source = addSource(r''' | 507 Source source = addSource(r''' |
| 498 a(b(int p)) { | 508 a(b(int p)) { |
| 499 b('0'); | 509 b('0'); |
| 500 }'''); | 510 }'''); |
| 501 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 511 await assertErrors( |
| 512 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 502 verify([source]); | 513 verify([source]); |
| 503 } | 514 } |
| 504 | 515 |
| 505 void test_argumentTypeNotAssignable_invocation_functionParameter_generic() { | 516 test_argumentTypeNotAssignable_invocation_functionParameter_generic() async { |
| 506 Source source = addSource(r''' | 517 Source source = addSource(r''' |
| 507 class A<K, V> { | 518 class A<K, V> { |
| 508 m(f(K k), V v) { | 519 m(f(K k), V v) { |
| 509 f(v); | 520 f(v); |
| 510 } | 521 } |
| 511 }'''); | 522 }'''); |
| 512 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 523 await assertErrors( |
| 524 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 513 verify([source]); | 525 verify([source]); |
| 514 } | 526 } |
| 515 | 527 |
| 516 void test_argumentTypeNotAssignable_invocation_functionTypes_optional() { | 528 test_argumentTypeNotAssignable_invocation_functionTypes_optional() async { |
| 517 Source source = addSource(r''' | 529 Source source = addSource(r''' |
| 518 void acceptFunNumOptBool(void funNumOptBool([bool b])) {} | 530 void acceptFunNumOptBool(void funNumOptBool([bool b])) {} |
| 519 void funNumBool(bool b) {} | 531 void funNumBool(bool b) {} |
| 520 main() { | 532 main() { |
| 521 acceptFunNumOptBool(funNumBool); | 533 acceptFunNumOptBool(funNumBool); |
| 522 }'''); | 534 }'''); |
| 523 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 535 await assertErrors( |
| 536 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 524 verify([source]); | 537 verify([source]); |
| 525 } | 538 } |
| 526 | 539 |
| 527 void test_argumentTypeNotAssignable_invocation_generic() { | 540 test_argumentTypeNotAssignable_invocation_generic() async { |
| 528 Source source = addSource(r''' | 541 Source source = addSource(r''' |
| 529 class A<T> { | 542 class A<T> { |
| 530 m(T t) {} | 543 m(T t) {} |
| 531 } | 544 } |
| 532 f(A<String> a) { | 545 f(A<String> a) { |
| 533 a.m(1); | 546 a.m(1); |
| 534 }'''); | 547 }'''); |
| 535 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 548 await assertErrors( |
| 549 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 536 verify([source]); | 550 verify([source]); |
| 537 } | 551 } |
| 538 | 552 |
| 539 void test_argumentTypeNotAssignable_invocation_named() { | 553 test_argumentTypeNotAssignable_invocation_named() async { |
| 540 Source source = addSource(r''' | 554 Source source = addSource(r''' |
| 541 f({String p}) {} | 555 f({String p}) {} |
| 542 main() { | 556 main() { |
| 543 f(p: 42); | 557 f(p: 42); |
| 544 }'''); | 558 }'''); |
| 545 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 559 await assertErrors( |
| 560 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 546 verify([source]); | 561 verify([source]); |
| 547 } | 562 } |
| 548 | 563 |
| 549 void test_argumentTypeNotAssignable_invocation_optional() { | 564 test_argumentTypeNotAssignable_invocation_optional() async { |
| 550 Source source = addSource(r''' | 565 Source source = addSource(r''' |
| 551 f([String p]) {} | 566 f([String p]) {} |
| 552 main() { | 567 main() { |
| 553 f(42); | 568 f(42); |
| 554 }'''); | 569 }'''); |
| 555 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 570 await assertErrors( |
| 571 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 556 verify([source]); | 572 verify([source]); |
| 557 } | 573 } |
| 558 | 574 |
| 559 void test_argumentTypeNotAssignable_invocation_required() { | 575 test_argumentTypeNotAssignable_invocation_required() async { |
| 560 Source source = addSource(r''' | 576 Source source = addSource(r''' |
| 561 f(String p) {} | 577 f(String p) {} |
| 562 main() { | 578 main() { |
| 563 f(42); | 579 f(42); |
| 564 }'''); | 580 }'''); |
| 565 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 581 await assertErrors( |
| 582 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 566 verify([source]); | 583 verify([source]); |
| 567 } | 584 } |
| 568 | 585 |
| 569 void test_argumentTypeNotAssignable_invocation_typedef_generic() { | 586 test_argumentTypeNotAssignable_invocation_typedef_generic() async { |
| 570 Source source = addSource(r''' | 587 Source source = addSource(r''' |
| 571 typedef A<T>(T p); | 588 typedef A<T>(T p); |
| 572 f(A<int> a) { | 589 f(A<int> a) { |
| 573 a('1'); | 590 a('1'); |
| 574 }'''); | 591 }'''); |
| 575 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 592 await assertErrors( |
| 593 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 576 verify([source]); | 594 verify([source]); |
| 577 } | 595 } |
| 578 | 596 |
| 579 void test_argumentTypeNotAssignable_invocation_typedef_local() { | 597 test_argumentTypeNotAssignable_invocation_typedef_local() async { |
| 580 Source source = addSource(r''' | 598 Source source = addSource(r''' |
| 581 typedef A(int p); | 599 typedef A(int p); |
| 582 A getA() => null; | 600 A getA() => null; |
| 583 main() { | 601 main() { |
| 584 A a = getA(); | 602 A a = getA(); |
| 585 a('1'); | 603 a('1'); |
| 586 }'''); | 604 }'''); |
| 587 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 605 await assertErrors( |
| 606 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 588 verify([source]); | 607 verify([source]); |
| 589 } | 608 } |
| 590 | 609 |
| 591 void test_argumentTypeNotAssignable_invocation_typedef_parameter() { | 610 test_argumentTypeNotAssignable_invocation_typedef_parameter() async { |
| 592 Source source = addSource(r''' | 611 Source source = addSource(r''' |
| 593 typedef A(int p); | 612 typedef A(int p); |
| 594 f(A a) { | 613 f(A a) { |
| 595 a('1'); | 614 a('1'); |
| 596 }'''); | 615 }'''); |
| 597 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 616 await assertErrors( |
| 617 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 598 verify([source]); | 618 verify([source]); |
| 599 } | 619 } |
| 600 | 620 |
| 601 void test_argumentTypeNotAssignable_new_generic() { | 621 test_argumentTypeNotAssignable_new_generic() async { |
| 602 Source source = addSource(r''' | 622 Source source = addSource(r''' |
| 603 class A<T> { | 623 class A<T> { |
| 604 A(T p) {} | 624 A(T p) {} |
| 605 } | 625 } |
| 606 main() { | 626 main() { |
| 607 new A<String>(42); | 627 new A<String>(42); |
| 608 }'''); | 628 }'''); |
| 609 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 629 await assertErrors( |
| 630 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 610 verify([source]); | 631 verify([source]); |
| 611 } | 632 } |
| 612 | 633 |
| 613 void test_argumentTypeNotAssignable_new_optional() { | 634 test_argumentTypeNotAssignable_new_optional() async { |
| 614 Source source = addSource(r''' | 635 Source source = addSource(r''' |
| 615 class A { | 636 class A { |
| 616 A([String p]) {} | 637 A([String p]) {} |
| 617 } | 638 } |
| 618 main() { | 639 main() { |
| 619 new A(42); | 640 new A(42); |
| 620 }'''); | 641 }'''); |
| 621 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 642 await assertErrors( |
| 643 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 622 verify([source]); | 644 verify([source]); |
| 623 } | 645 } |
| 624 | 646 |
| 625 void test_argumentTypeNotAssignable_new_required() { | 647 test_argumentTypeNotAssignable_new_required() async { |
| 626 Source source = addSource(r''' | 648 Source source = addSource(r''' |
| 627 class A { | 649 class A { |
| 628 A(String p) {} | 650 A(String p) {} |
| 629 } | 651 } |
| 630 main() { | 652 main() { |
| 631 new A(42); | 653 new A(42); |
| 632 }'''); | 654 }'''); |
| 633 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 655 await assertErrors( |
| 656 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 634 verify([source]); | 657 verify([source]); |
| 635 } | 658 } |
| 636 | 659 |
| 637 void test_assignmentToClass() { | 660 test_assignmentToClass() async { |
| 638 Source source = addSource(''' | 661 Source source = addSource(''' |
| 639 class C {} | 662 class C {} |
| 640 main() { | 663 main() { |
| 641 C = null; | 664 C = null; |
| 642 } | 665 } |
| 643 '''); | 666 '''); |
| 644 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); | 667 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); |
| 645 } | 668 } |
| 646 | 669 |
| 647 void test_assignmentToConst_instanceVariable() { | 670 test_assignmentToConst_instanceVariable() async { |
| 648 Source source = addSource(r''' | 671 Source source = addSource(r''' |
| 649 class A { | 672 class A { |
| 650 static const v = 0; | 673 static const v = 0; |
| 651 } | 674 } |
| 652 f() { | 675 f() { |
| 653 A.v = 1; | 676 A.v = 1; |
| 654 }'''); | 677 }'''); |
| 655 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); | 678 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); |
| 656 verify([source]); | 679 verify([source]); |
| 657 } | 680 } |
| 658 | 681 |
| 659 void test_assignmentToConst_instanceVariable_plusEq() { | 682 test_assignmentToConst_instanceVariable_plusEq() async { |
| 660 Source source = addSource(r''' | 683 Source source = addSource(r''' |
| 661 class A { | 684 class A { |
| 662 static const v = 0; | 685 static const v = 0; |
| 663 } | 686 } |
| 664 f() { | 687 f() { |
| 665 A.v += 1; | 688 A.v += 1; |
| 666 }'''); | 689 }'''); |
| 667 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); | 690 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); |
| 668 verify([source]); | 691 verify([source]); |
| 669 } | 692 } |
| 670 | 693 |
| 671 void test_assignmentToConst_localVariable() { | 694 test_assignmentToConst_localVariable() async { |
| 672 Source source = addSource(r''' | 695 Source source = addSource(r''' |
| 673 f() { | 696 f() { |
| 674 const x = 0; | 697 const x = 0; |
| 675 x = 1; | 698 x = 1; |
| 676 }'''); | 699 }'''); |
| 677 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); | 700 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); |
| 678 verify([source]); | 701 verify([source]); |
| 679 } | 702 } |
| 680 | 703 |
| 681 void test_assignmentToConst_localVariable_plusEq() { | 704 test_assignmentToConst_localVariable_plusEq() async { |
| 682 Source source = addSource(r''' | 705 Source source = addSource(r''' |
| 683 f() { | 706 f() { |
| 684 const x = 0; | 707 const x = 0; |
| 685 x += 1; | 708 x += 1; |
| 686 }'''); | 709 }'''); |
| 687 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); | 710 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); |
| 688 verify([source]); | 711 verify([source]); |
| 689 } | 712 } |
| 690 | 713 |
| 691 void test_assignmentToEnumType() { | 714 test_assignmentToEnumType() async { |
| 692 Source source = addSource(''' | 715 Source source = addSource(''' |
| 693 enum E { e } | 716 enum E { e } |
| 694 main() { | 717 main() { |
| 695 E = null; | 718 E = null; |
| 696 } | 719 } |
| 697 '''); | 720 '''); |
| 698 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); | 721 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); |
| 699 } | 722 } |
| 700 | 723 |
| 701 void test_assignmentToFinal_instanceVariable() { | 724 test_assignmentToFinal_instanceVariable() async { |
| 702 Source source = addSource(r''' | 725 Source source = addSource(r''' |
| 703 class A { | 726 class A { |
| 704 final v = 0; | 727 final v = 0; |
| 705 } | 728 } |
| 706 f() { | 729 f() { |
| 707 A a = new A(); | 730 A a = new A(); |
| 708 a.v = 1; | 731 a.v = 1; |
| 709 }'''); | 732 }'''); |
| 710 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 733 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 711 verify([source]); | 734 verify([source]); |
| 712 } | 735 } |
| 713 | 736 |
| 714 void test_assignmentToFinal_instanceVariable_plusEq() { | 737 test_assignmentToFinal_instanceVariable_plusEq() async { |
| 715 Source source = addSource(r''' | 738 Source source = addSource(r''' |
| 716 class A { | 739 class A { |
| 717 final v = 0; | 740 final v = 0; |
| 718 } | 741 } |
| 719 f() { | 742 f() { |
| 720 A a = new A(); | 743 A a = new A(); |
| 721 a.v += 1; | 744 a.v += 1; |
| 722 }'''); | 745 }'''); |
| 723 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 746 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 724 verify([source]); | 747 verify([source]); |
| 725 } | 748 } |
| 726 | 749 |
| 727 void test_assignmentToFinal_localVariable() { | 750 test_assignmentToFinal_localVariable() async { |
| 728 Source source = addSource(r''' | 751 Source source = addSource(r''' |
| 729 f() { | 752 f() { |
| 730 final x = 0; | 753 final x = 0; |
| 731 x = 1; | 754 x = 1; |
| 732 }'''); | 755 }'''); |
| 733 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 756 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 734 verify([source]); | 757 verify([source]); |
| 735 } | 758 } |
| 736 | 759 |
| 737 void test_assignmentToFinal_localVariable_plusEq() { | 760 test_assignmentToFinal_localVariable_plusEq() async { |
| 738 Source source = addSource(r''' | 761 Source source = addSource(r''' |
| 739 f() { | 762 f() { |
| 740 final x = 0; | 763 final x = 0; |
| 741 x += 1; | 764 x += 1; |
| 742 }'''); | 765 }'''); |
| 743 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 766 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 744 verify([source]); | 767 verify([source]); |
| 745 } | 768 } |
| 746 | 769 |
| 747 void test_assignmentToFinal_postfixMinusMinus() { | 770 test_assignmentToFinal_postfixMinusMinus() async { |
| 748 Source source = addSource(r''' | 771 Source source = addSource(r''' |
| 749 f() { | 772 f() { |
| 750 final x = 0; | 773 final x = 0; |
| 751 x--; | 774 x--; |
| 752 }'''); | 775 }'''); |
| 753 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 776 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 754 verify([source]); | 777 verify([source]); |
| 755 } | 778 } |
| 756 | 779 |
| 757 void test_assignmentToFinal_postfixPlusPlus() { | 780 test_assignmentToFinal_postfixPlusPlus() async { |
| 758 Source source = addSource(r''' | 781 Source source = addSource(r''' |
| 759 f() { | 782 f() { |
| 760 final x = 0; | 783 final x = 0; |
| 761 x++; | 784 x++; |
| 762 }'''); | 785 }'''); |
| 763 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 786 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 764 verify([source]); | 787 verify([source]); |
| 765 } | 788 } |
| 766 | 789 |
| 767 void test_assignmentToFinal_prefixMinusMinus() { | 790 test_assignmentToFinal_prefixMinusMinus() async { |
| 768 Source source = addSource(r''' | 791 Source source = addSource(r''' |
| 769 f() { | 792 f() { |
| 770 final x = 0; | 793 final x = 0; |
| 771 --x; | 794 --x; |
| 772 }'''); | 795 }'''); |
| 773 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 796 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 774 verify([source]); | 797 verify([source]); |
| 775 } | 798 } |
| 776 | 799 |
| 777 void test_assignmentToFinal_prefixPlusPlus() { | 800 test_assignmentToFinal_prefixPlusPlus() async { |
| 778 Source source = addSource(r''' | 801 Source source = addSource(r''' |
| 779 f() { | 802 f() { |
| 780 final x = 0; | 803 final x = 0; |
| 781 ++x; | 804 ++x; |
| 782 }'''); | 805 }'''); |
| 783 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 806 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 784 verify([source]); | 807 verify([source]); |
| 785 } | 808 } |
| 786 | 809 |
| 787 void test_assignmentToFinal_suffixMinusMinus() { | 810 test_assignmentToFinal_suffixMinusMinus() async { |
| 788 Source source = addSource(r''' | 811 Source source = addSource(r''' |
| 789 f() { | 812 f() { |
| 790 final x = 0; | 813 final x = 0; |
| 791 x--; | 814 x--; |
| 792 }'''); | 815 }'''); |
| 793 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 816 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 794 verify([source]); | 817 verify([source]); |
| 795 } | 818 } |
| 796 | 819 |
| 797 void test_assignmentToFinal_suffixPlusPlus() { | 820 test_assignmentToFinal_suffixPlusPlus() async { |
| 798 Source source = addSource(r''' | 821 Source source = addSource(r''' |
| 799 f() { | 822 f() { |
| 800 final x = 0; | 823 final x = 0; |
| 801 x++; | 824 x++; |
| 802 }'''); | 825 }'''); |
| 803 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 826 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 804 verify([source]); | 827 verify([source]); |
| 805 } | 828 } |
| 806 | 829 |
| 807 void test_assignmentToFinal_topLevelVariable() { | 830 test_assignmentToFinal_topLevelVariable() async { |
| 808 Source source = addSource(r''' | 831 Source source = addSource(r''' |
| 809 final x = 0; | 832 final x = 0; |
| 810 f() { x = 1; }'''); | 833 f() { x = 1; }'''); |
| 811 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); | 834 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); |
| 812 verify([source]); | 835 verify([source]); |
| 813 } | 836 } |
| 814 | 837 |
| 815 void test_assignmentToFinalNoSetter_prefixedIdentifier() { | 838 test_assignmentToFinalNoSetter_prefixedIdentifier() async { |
| 816 Source source = addSource(r''' | 839 Source source = addSource(r''' |
| 817 class A { | 840 class A { |
| 818 int get x => 0; | 841 int get x => 0; |
| 819 } | 842 } |
| 820 main() { | 843 main() { |
| 821 A a = new A(); | 844 A a = new A(); |
| 822 a.x = 0; | 845 a.x = 0; |
| 823 }'''); | 846 }'''); |
| 824 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]); | 847 await assertErrors( |
| 848 source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]); |
| 825 verify([source]); | 849 verify([source]); |
| 826 } | 850 } |
| 827 | 851 |
| 828 void test_assignmentToFinalNoSetter_propertyAccess() { | 852 test_assignmentToFinalNoSetter_propertyAccess() async { |
| 829 Source source = addSource(r''' | 853 Source source = addSource(r''' |
| 830 class A { | 854 class A { |
| 831 int get x => 0; | 855 int get x => 0; |
| 832 } | 856 } |
| 833 class B { | 857 class B { |
| 834 static A a; | 858 static A a; |
| 835 } | 859 } |
| 836 main() { | 860 main() { |
| 837 B.a.x = 0; | 861 B.a.x = 0; |
| 838 }'''); | 862 }'''); |
| 839 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]); | 863 await assertErrors( |
| 864 source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]); |
| 840 verify([source]); | 865 verify([source]); |
| 841 } | 866 } |
| 842 | 867 |
| 843 void test_assignmentToFunction() { | 868 test_assignmentToFunction() async { |
| 844 Source source = addSource(r''' | 869 Source source = addSource(r''' |
| 845 f() {} | 870 f() {} |
| 846 main() { | 871 main() { |
| 847 f = null; | 872 f = null; |
| 848 }'''); | 873 }'''); |
| 849 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FUNCTION]); | 874 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FUNCTION]); |
| 850 verify([source]); | 875 verify([source]); |
| 851 } | 876 } |
| 852 | 877 |
| 853 void test_assignmentToMethod() { | 878 test_assignmentToMethod() async { |
| 854 Source source = addSource(r''' | 879 Source source = addSource(r''' |
| 855 class A { | 880 class A { |
| 856 m() {} | 881 m() {} |
| 857 } | 882 } |
| 858 f(A a) { | 883 f(A a) { |
| 859 a.m = () {}; | 884 a.m = () {}; |
| 860 }'''); | 885 }'''); |
| 861 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_METHOD]); | 886 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_METHOD]); |
| 862 verify([source]); | 887 verify([source]); |
| 863 } | 888 } |
| 864 | 889 |
| 865 void test_assignmentToTypedef() { | 890 test_assignmentToTypedef() async { |
| 866 Source source = addSource(''' | 891 Source source = addSource(''' |
| 867 typedef void F(); | 892 typedef void F(); |
| 868 main() { | 893 main() { |
| 869 F = null; | 894 F = null; |
| 870 } | 895 } |
| 871 '''); | 896 '''); |
| 872 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); | 897 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); |
| 873 } | 898 } |
| 874 | 899 |
| 875 void test_assignmentToTypeParameter() { | 900 test_assignmentToTypeParameter() async { |
| 876 Source source = addSource(''' | 901 Source source = addSource(''' |
| 877 class C<T> { | 902 class C<T> { |
| 878 f() { | 903 f() { |
| 879 T = null; | 904 T = null; |
| 880 } | 905 } |
| 881 } | 906 } |
| 882 '''); | 907 '''); |
| 883 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); | 908 await assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); |
| 884 } | 909 } |
| 885 | 910 |
| 886 void test_caseBlockNotTerminated() { | 911 test_caseBlockNotTerminated() async { |
| 887 Source source = addSource(r''' | 912 Source source = addSource(r''' |
| 888 f(int p) { | 913 f(int p) { |
| 889 switch (p) { | 914 switch (p) { |
| 890 case 0: | 915 case 0: |
| 891 f(p); | 916 f(p); |
| 892 case 1: | 917 case 1: |
| 893 break; | 918 break; |
| 894 } | 919 } |
| 895 }'''); | 920 }'''); |
| 896 assertErrors(source, [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]); | 921 await assertErrors(source, [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]); |
| 897 verify([source]); | 922 verify([source]); |
| 898 } | 923 } |
| 899 | 924 |
| 900 void test_castToNonType() { | 925 test_castToNonType() async { |
| 901 Source source = addSource(r''' | 926 Source source = addSource(r''' |
| 902 var A = 0; | 927 var A = 0; |
| 903 f(String s) { var x = s as A; }'''); | 928 f(String s) { var x = s as A; }'''); |
| 904 assertErrors(source, [StaticWarningCode.CAST_TO_NON_TYPE]); | 929 await assertErrors(source, [StaticWarningCode.CAST_TO_NON_TYPE]); |
| 905 verify([source]); | 930 verify([source]); |
| 906 } | 931 } |
| 907 | 932 |
| 908 void test_concreteClassWithAbstractMember() { | 933 test_concreteClassWithAbstractMember() async { |
| 909 Source source = addSource(r''' | 934 Source source = addSource(r''' |
| 910 class A { | 935 class A { |
| 911 m(); | 936 m(); |
| 912 }'''); | 937 }'''); |
| 913 assertErrors( | 938 await assertErrors( |
| 914 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); | 939 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); |
| 915 verify([source]); | 940 verify([source]); |
| 916 } | 941 } |
| 917 | 942 |
| 918 void test_concreteClassWithAbstractMember_noSuchMethod_interface() { | 943 test_concreteClassWithAbstractMember_noSuchMethod_interface() async { |
| 919 Source source = addSource(r''' | 944 Source source = addSource(r''' |
| 920 class I { | 945 class I { |
| 921 noSuchMethod(v) => ''; | 946 noSuchMethod(v) => ''; |
| 922 } | 947 } |
| 923 class A implements I { | 948 class A implements I { |
| 924 m(); | 949 m(); |
| 925 }'''); | 950 }'''); |
| 926 assertErrors( | 951 await assertErrors( |
| 927 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); | 952 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); |
| 928 verify([source]); | 953 verify([source]); |
| 929 } | 954 } |
| 930 | 955 |
| 931 void test_conflictingDartImport() { | 956 test_conflictingDartImport() async { |
| 932 Source source = addSource(r''' | 957 Source source = addSource(r''' |
| 933 import 'lib.dart'; | 958 import 'lib.dart'; |
| 934 import 'dart:async'; | 959 import 'dart:async'; |
| 935 Future f = null; | 960 Future f = null; |
| 936 Stream s;'''); | 961 Stream s;'''); |
| 937 addNamedSource( | 962 addNamedSource( |
| 938 "/lib.dart", | 963 "/lib.dart", |
| 939 r''' | 964 r''' |
| 940 library lib; | 965 library lib; |
| 941 class Future {}'''); | 966 class Future {}'''); |
| 942 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]); | 967 await assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]); |
| 943 } | 968 } |
| 944 | 969 |
| 945 void | 970 test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter() as
ync { |
| 946 test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter(
) { | |
| 947 Source source = addSource(r''' | 971 Source source = addSource(r''' |
| 948 class A { | 972 class A { |
| 949 static set v(x) {} | 973 static set v(x) {} |
| 950 } | 974 } |
| 951 class B extends A { | 975 class B extends A { |
| 952 var v; | 976 var v; |
| 953 }'''); | 977 }'''); |
| 954 assertErrors(source, | 978 await assertErrors(source, |
| 955 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 979 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 956 verify([source]); | 980 verify([source]); |
| 957 } | 981 } |
| 958 | 982 |
| 959 void | 983 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_getter() a
sync { |
| 960 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_getter
() { | |
| 961 Source source = addSource(r''' | 984 Source source = addSource(r''' |
| 962 class A { | 985 class A { |
| 963 static get v => 0; | 986 static get v => 0; |
| 964 } | 987 } |
| 965 class B extends A { | 988 class B extends A { |
| 966 get v => 0; | 989 get v => 0; |
| 967 }'''); | 990 }'''); |
| 968 assertErrors(source, | 991 await assertErrors(source, |
| 969 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 992 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 970 verify([source]); | 993 verify([source]); |
| 971 } | 994 } |
| 972 | 995 |
| 973 void | 996 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_method() a
sync { |
| 974 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_method
() { | |
| 975 Source source = addSource(r''' | 997 Source source = addSource(r''' |
| 976 class A { | 998 class A { |
| 977 static v() {} | 999 static v() {} |
| 978 } | 1000 } |
| 979 class B extends A { | 1001 class B extends A { |
| 980 get v => 0; | 1002 get v => 0; |
| 981 }'''); | 1003 }'''); |
| 982 assertErrors(source, | 1004 await assertErrors(source, |
| 983 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1005 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 984 verify([source]); | 1006 verify([source]); |
| 985 } | 1007 } |
| 986 | 1008 |
| 987 void | 1009 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_setter() a
sync { |
| 988 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_setter
() { | |
| 989 Source source = addSource(r''' | 1010 Source source = addSource(r''' |
| 990 class A { | 1011 class A { |
| 991 static set v(x) {} | 1012 static set v(x) {} |
| 992 } | 1013 } |
| 993 class B extends A { | 1014 class B extends A { |
| 994 get v => 0; | 1015 get v => 0; |
| 995 }'''); | 1016 }'''); |
| 996 assertErrors(source, | 1017 await assertErrors(source, |
| 997 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1018 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 998 verify([source]); | 1019 verify([source]); |
| 999 } | 1020 } |
| 1000 | 1021 |
| 1001 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_indirect() { | 1022 test_conflictingInstanceGetterAndSuperclassMember_declGetter_indirect() async
{ |
| 1002 Source source = addSource(r''' | 1023 Source source = addSource(r''' |
| 1003 class A { | 1024 class A { |
| 1004 static int v; | 1025 static int v; |
| 1005 } | 1026 } |
| 1006 class B extends A {} | 1027 class B extends A {} |
| 1007 class C extends B { | 1028 class C extends B { |
| 1008 get v => 0; | 1029 get v => 0; |
| 1009 }'''); | 1030 }'''); |
| 1010 assertErrors(source, | 1031 await assertErrors(source, |
| 1011 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1032 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 1012 verify([source]); | 1033 verify([source]); |
| 1013 } | 1034 } |
| 1014 | 1035 |
| 1015 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_mixin() { | 1036 test_conflictingInstanceGetterAndSuperclassMember_declGetter_mixin() async { |
| 1016 Source source = addSource(r''' | 1037 Source source = addSource(r''' |
| 1017 class M { | 1038 class M { |
| 1018 static int v; | 1039 static int v; |
| 1019 } | 1040 } |
| 1020 class B extends Object with M { | 1041 class B extends Object with M { |
| 1021 get v => 0; | 1042 get v => 0; |
| 1022 }'''); | 1043 }'''); |
| 1023 assertErrors(source, | 1044 await assertErrors(source, |
| 1024 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1045 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 1025 verify([source]); | 1046 verify([source]); |
| 1026 } | 1047 } |
| 1027 | 1048 |
| 1028 void test_conflictingInstanceGetterAndSuperclassMember_direct_field() { | 1049 test_conflictingInstanceGetterAndSuperclassMember_direct_field() async { |
| 1029 Source source = addSource(r''' | 1050 Source source = addSource(r''' |
| 1030 class A { | 1051 class A { |
| 1031 static int v; | 1052 static int v; |
| 1032 } | 1053 } |
| 1033 class B extends A { | 1054 class B extends A { |
| 1034 get v => 0; | 1055 get v => 0; |
| 1035 }'''); | 1056 }'''); |
| 1036 assertErrors(source, | 1057 await assertErrors(source, |
| 1037 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1058 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 1038 verify([source]); | 1059 verify([source]); |
| 1039 } | 1060 } |
| 1040 | 1061 |
| 1041 void test_conflictingInstanceMethodSetter2() { | 1062 test_conflictingInstanceMethodSetter2() async { |
| 1042 Source source = addSource(r''' | 1063 Source source = addSource(r''' |
| 1043 class A { | 1064 class A { |
| 1044 foo() {} | 1065 foo() {} |
| 1045 set foo(a) {} | 1066 set foo(a) {} |
| 1046 }'''); | 1067 }'''); |
| 1047 assertErrors( | 1068 await assertErrors( |
| 1048 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2]); | 1069 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2]); |
| 1049 verify([source]); | 1070 verify([source]); |
| 1050 } | 1071 } |
| 1051 | 1072 |
| 1052 void test_conflictingInstanceMethodSetter_sameClass() { | 1073 test_conflictingInstanceMethodSetter_sameClass() async { |
| 1053 Source source = addSource(r''' | 1074 Source source = addSource(r''' |
| 1054 class A { | 1075 class A { |
| 1055 set foo(a) {} | 1076 set foo(a) {} |
| 1056 foo() {} | 1077 foo() {} |
| 1057 }'''); | 1078 }'''); |
| 1058 assertErrors( | 1079 await assertErrors( |
| 1059 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); | 1080 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); |
| 1060 verify([source]); | 1081 verify([source]); |
| 1061 } | 1082 } |
| 1062 | 1083 |
| 1063 void test_conflictingInstanceMethodSetter_setterInInterface() { | 1084 test_conflictingInstanceMethodSetter_setterInInterface() async { |
| 1064 Source source = addSource(r''' | 1085 Source source = addSource(r''' |
| 1065 abstract class A { | 1086 abstract class A { |
| 1066 set foo(a); | 1087 set foo(a); |
| 1067 } | 1088 } |
| 1068 abstract class B implements A { | 1089 abstract class B implements A { |
| 1069 foo() {} | 1090 foo() {} |
| 1070 }'''); | 1091 }'''); |
| 1071 assertErrors( | 1092 await assertErrors( |
| 1072 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); | 1093 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); |
| 1073 verify([source]); | 1094 verify([source]); |
| 1074 } | 1095 } |
| 1075 | 1096 |
| 1076 void test_conflictingInstanceMethodSetter_setterInSuper() { | 1097 test_conflictingInstanceMethodSetter_setterInSuper() async { |
| 1077 Source source = addSource(r''' | 1098 Source source = addSource(r''' |
| 1078 class A { | 1099 class A { |
| 1079 set foo(a) {} | 1100 set foo(a) {} |
| 1080 } | 1101 } |
| 1081 class B extends A { | 1102 class B extends A { |
| 1082 foo() {} | 1103 foo() {} |
| 1083 }'''); | 1104 }'''); |
| 1084 assertErrors( | 1105 await assertErrors( |
| 1085 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); | 1106 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); |
| 1086 verify([source]); | 1107 verify([source]); |
| 1087 } | 1108 } |
| 1088 | 1109 |
| 1089 void test_conflictingInstanceSetterAndSuperclassMember() { | 1110 test_conflictingInstanceSetterAndSuperclassMember() async { |
| 1090 Source source = addSource(r''' | 1111 Source source = addSource(r''' |
| 1091 class A { | 1112 class A { |
| 1092 static int v; | 1113 static int v; |
| 1093 } | 1114 } |
| 1094 class B extends A { | 1115 class B extends A { |
| 1095 set v(x) {} | 1116 set v(x) {} |
| 1096 }'''); | 1117 }'''); |
| 1097 assertErrors(source, | 1118 await assertErrors(source, |
| 1098 [StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER]); | 1119 [StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER]); |
| 1099 verify([source]); | 1120 verify([source]); |
| 1100 } | 1121 } |
| 1101 | 1122 |
| 1102 void test_conflictingStaticGetterAndInstanceSetter_mixin() { | 1123 test_conflictingStaticGetterAndInstanceSetter_mixin() async { |
| 1103 Source source = addSource(r''' | 1124 Source source = addSource(r''' |
| 1104 class A { | 1125 class A { |
| 1105 set x(int p) {} | 1126 set x(int p) {} |
| 1106 } | 1127 } |
| 1107 class B extends Object with A { | 1128 class B extends Object with A { |
| 1108 static get x => 0; | 1129 static get x => 0; |
| 1109 }'''); | 1130 }'''); |
| 1110 assertErrors(source, | 1131 await assertErrors(source, |
| 1111 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); | 1132 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); |
| 1112 verify([source]); | 1133 verify([source]); |
| 1113 } | 1134 } |
| 1114 | 1135 |
| 1115 void test_conflictingStaticGetterAndInstanceSetter_superClass() { | 1136 test_conflictingStaticGetterAndInstanceSetter_superClass() async { |
| 1116 Source source = addSource(r''' | 1137 Source source = addSource(r''' |
| 1117 class A { | 1138 class A { |
| 1118 set x(int p) {} | 1139 set x(int p) {} |
| 1119 } | 1140 } |
| 1120 class B extends A { | 1141 class B extends A { |
| 1121 static get x => 0; | 1142 static get x => 0; |
| 1122 }'''); | 1143 }'''); |
| 1123 assertErrors(source, | 1144 await assertErrors(source, |
| 1124 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); | 1145 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); |
| 1125 verify([source]); | 1146 verify([source]); |
| 1126 } | 1147 } |
| 1127 | 1148 |
| 1128 void test_conflictingStaticGetterAndInstanceSetter_thisClass() { | 1149 test_conflictingStaticGetterAndInstanceSetter_thisClass() async { |
| 1129 Source source = addSource(r''' | 1150 Source source = addSource(r''' |
| 1130 class A { | 1151 class A { |
| 1131 static get x => 0; | 1152 static get x => 0; |
| 1132 set x(int p) {} | 1153 set x(int p) {} |
| 1133 }'''); | 1154 }'''); |
| 1134 assertErrors(source, | 1155 await assertErrors(source, |
| 1135 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); | 1156 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); |
| 1136 verify([source]); | 1157 verify([source]); |
| 1137 } | 1158 } |
| 1138 | 1159 |
| 1139 void test_conflictingStaticSetterAndInstanceMember_thisClass_getter() { | 1160 test_conflictingStaticSetterAndInstanceMember_thisClass_getter() async { |
| 1140 Source source = addSource(r''' | 1161 Source source = addSource(r''' |
| 1141 class A { | 1162 class A { |
| 1142 get x => 0; | 1163 get x => 0; |
| 1143 static set x(int p) {} | 1164 static set x(int p) {} |
| 1144 }'''); | 1165 }'''); |
| 1145 assertErrors(source, | 1166 await assertErrors(source, |
| 1146 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]); | 1167 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]); |
| 1147 verify([source]); | 1168 verify([source]); |
| 1148 } | 1169 } |
| 1149 | 1170 |
| 1150 void test_conflictingStaticSetterAndInstanceMember_thisClass_method() { | 1171 test_conflictingStaticSetterAndInstanceMember_thisClass_method() async { |
| 1151 Source source = addSource(r''' | 1172 Source source = addSource(r''' |
| 1152 class A { | 1173 class A { |
| 1153 x() {} | 1174 x() {} |
| 1154 static set x(int p) {} | 1175 static set x(int p) {} |
| 1155 }'''); | 1176 }'''); |
| 1156 assertErrors(source, | 1177 await assertErrors(source, |
| 1157 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]); | 1178 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]); |
| 1158 verify([source]); | 1179 verify([source]); |
| 1159 } | 1180 } |
| 1160 | 1181 |
| 1161 void test_constWithAbstractClass() { | 1182 test_constWithAbstractClass() async { |
| 1162 Source source = addSource(r''' | 1183 Source source = addSource(r''' |
| 1163 abstract class A { | 1184 abstract class A { |
| 1164 const A(); | 1185 const A(); |
| 1165 } | 1186 } |
| 1166 void f() { | 1187 void f() { |
| 1167 A a = const A(); | 1188 A a = const A(); |
| 1168 }'''); | 1189 }'''); |
| 1169 assertErrors(source, [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS]); | 1190 await assertErrors(source, [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS]); |
| 1170 verify([source]); | 1191 verify([source]); |
| 1171 } | 1192 } |
| 1172 | 1193 |
| 1173 void test_equalKeysInMap() { | 1194 test_equalKeysInMap() async { |
| 1174 Source source = addSource("var m = {'a' : 0, 'b' : 1, 'a' : 2};"); | 1195 Source source = addSource("var m = {'a' : 0, 'b' : 1, 'a' : 2};"); |
| 1175 assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]); | 1196 await assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]); |
| 1176 verify([source]); | 1197 verify([source]); |
| 1177 } | 1198 } |
| 1178 | 1199 |
| 1179 void test_equalKeysInMap_withEqualTypeParams() { | 1200 test_equalKeysInMap_withEqualTypeParams() async { |
| 1180 Source source = addSource(r''' | 1201 Source source = addSource(r''' |
| 1181 class A<T> { | 1202 class A<T> { |
| 1182 const A(); | 1203 const A(); |
| 1183 } | 1204 } |
| 1184 var m = {const A<int>(): 0, const A<int>(): 1};'''); | 1205 var m = {const A<int>(): 0, const A<int>(): 1};'''); |
| 1185 assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]); | 1206 await assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]); |
| 1186 verify([source]); | 1207 verify([source]); |
| 1187 } | 1208 } |
| 1188 | 1209 |
| 1189 void test_equalKeysInMap_withUnequalTypeParams() { | 1210 test_equalKeysInMap_withUnequalTypeParams() async { |
| 1190 // No error should be produced because A<int> and A<num> are different | 1211 // No error should be produced because A<int> and A<num> are different |
| 1191 // types. | 1212 // types. |
| 1192 Source source = addSource(r''' | 1213 Source source = addSource(r''' |
| 1193 class A<T> { | 1214 class A<T> { |
| 1194 const A(); | 1215 const A(); |
| 1195 } | 1216 } |
| 1196 var m = {const A<int>(): 0, const A<num>(): 1};'''); | 1217 var m = {const A<int>(): 0, const A<num>(): 1};'''); |
| 1197 assertNoErrors(source); | 1218 await assertNoErrors(source); |
| 1198 verify([source]); | 1219 verify([source]); |
| 1199 } | 1220 } |
| 1200 | 1221 |
| 1201 void test_exportDuplicatedLibraryNamed() { | 1222 test_exportDuplicatedLibraryNamed() async { |
| 1202 Source source = addSource(r''' | 1223 Source source = addSource(r''' |
| 1203 library test; | 1224 library test; |
| 1204 export 'lib1.dart'; | 1225 export 'lib1.dart'; |
| 1205 export 'lib2.dart';'''); | 1226 export 'lib2.dart';'''); |
| 1206 addNamedSource("/lib1.dart", "library lib;"); | 1227 addNamedSource("/lib1.dart", "library lib;"); |
| 1207 addNamedSource("/lib2.dart", "library lib;"); | 1228 addNamedSource("/lib2.dart", "library lib;"); |
| 1208 assertErrors(source, [StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_NAMED]); | 1229 await assertErrors( |
| 1230 source, [StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_NAMED]); |
| 1209 verify([source]); | 1231 verify([source]); |
| 1210 } | 1232 } |
| 1211 | 1233 |
| 1212 void test_extraPositionalArguments() { | 1234 test_extraPositionalArguments() async { |
| 1213 Source source = addSource(r''' | 1235 Source source = addSource(r''' |
| 1214 f() {} | 1236 f() {} |
| 1215 main() { | 1237 main() { |
| 1216 f(0, 1, '2'); | 1238 f(0, 1, '2'); |
| 1217 }'''); | 1239 }'''); |
| 1218 assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]); | 1240 await assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]); |
| 1219 verify([source]); | 1241 verify([source]); |
| 1220 } | 1242 } |
| 1221 | 1243 |
| 1222 void test_extraPositionalArguments_functionExpression() { | 1244 test_extraPositionalArguments_functionExpression() async { |
| 1223 Source source = addSource(r''' | 1245 Source source = addSource(r''' |
| 1224 main() { | 1246 main() { |
| 1225 (int x) {} (0, 1); | 1247 (int x) {} (0, 1); |
| 1226 }'''); | 1248 }'''); |
| 1227 assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]); | 1249 await assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]); |
| 1228 verify([source]); | 1250 verify([source]); |
| 1229 } | 1251 } |
| 1230 | 1252 |
| 1231 void test_fieldInitializedInInitializerAndDeclaration_final() { | 1253 test_fieldInitializedInInitializerAndDeclaration_final() async { |
| 1232 Source source = addSource(r''' | 1254 Source source = addSource(r''' |
| 1233 class A { | 1255 class A { |
| 1234 final int x = 0; | 1256 final int x = 0; |
| 1235 A() : x = 1 {} | 1257 A() : x = 1 {} |
| 1236 }'''); | 1258 }'''); |
| 1237 assertErrors(source, | 1259 await assertErrors(source, |
| 1238 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]); | 1260 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]); |
| 1239 verify([source]); | 1261 verify([source]); |
| 1240 } | 1262 } |
| 1241 | 1263 |
| 1242 void test_fieldInitializerNotAssignable() { | 1264 test_fieldInitializerNotAssignable() async { |
| 1243 Source source = addSource(r''' | 1265 Source source = addSource(r''' |
| 1244 class A { | 1266 class A { |
| 1245 int x; | 1267 int x; |
| 1246 A() : x = ''; | 1268 A() : x = ''; |
| 1247 }'''); | 1269 }'''); |
| 1248 assertErrors(source, [StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE]); | 1270 await assertErrors( |
| 1271 source, [StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE]); |
| 1249 verify([source]); | 1272 verify([source]); |
| 1250 } | 1273 } |
| 1251 | 1274 |
| 1252 void test_fieldInitializingFormalNotAssignable() { | 1275 test_fieldInitializingFormalNotAssignable() async { |
| 1253 Source source = addSource(r''' | 1276 Source source = addSource(r''' |
| 1254 class A { | 1277 class A { |
| 1255 int x; | 1278 int x; |
| 1256 A(String this.x) {} | 1279 A(String this.x) {} |
| 1257 }'''); | 1280 }'''); |
| 1258 assertErrors( | 1281 await assertErrors( |
| 1259 source, [StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]); | 1282 source, [StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]); |
| 1260 verify([source]); | 1283 verify([source]); |
| 1261 } | 1284 } |
| 1262 | 1285 |
| 1263 /** | 1286 /** |
| 1264 * This test doesn't test the FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR
code, but tests the | 1287 * This test doesn't test the FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR
code, but tests the |
| 1265 * FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION code instead. It is provid
ed here to show | 1288 * FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION code instead. It is provid
ed here to show |
| 1266 * coverage over all of the permutations of initializers in constructor declar
ations. | 1289 * coverage over all of the permutations of initializers in constructor declar
ations. |
| 1267 * | 1290 * |
| 1268 * Note: FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION covers a subset of | 1291 * Note: FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION covers a subset of |
| 1269 * FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR, since it more specific, w
e use it instead of | 1292 * FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR, since it more specific, w
e use it instead of |
| 1270 * the broader code | 1293 * the broader code |
| 1271 */ | 1294 */ |
| 1272 void test_finalInitializedInDeclarationAndConstructor_initializers() { | 1295 test_finalInitializedInDeclarationAndConstructor_initializers() async { |
| 1273 Source source = addSource(r''' | 1296 Source source = addSource(r''' |
| 1274 class A { | 1297 class A { |
| 1275 final x = 0; | 1298 final x = 0; |
| 1276 A() : x = 0 {} | 1299 A() : x = 0 {} |
| 1277 }'''); | 1300 }'''); |
| 1278 assertErrors(source, | 1301 await assertErrors(source, |
| 1279 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]); | 1302 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]); |
| 1280 verify([source]); | 1303 verify([source]); |
| 1281 } | 1304 } |
| 1282 | 1305 |
| 1283 void test_finalInitializedInDeclarationAndConstructor_initializingFormal() { | 1306 test_finalInitializedInDeclarationAndConstructor_initializingFormal() async { |
| 1284 Source source = addSource(r''' | 1307 Source source = addSource(r''' |
| 1285 class A { | 1308 class A { |
| 1286 final x = 0; | 1309 final x = 0; |
| 1287 A(this.x) {} | 1310 A(this.x) {} |
| 1288 }'''); | 1311 }'''); |
| 1289 assertErrors(source, | 1312 await assertErrors(source, |
| 1290 [StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR]); | 1313 [StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR]); |
| 1291 verify([source]); | 1314 verify([source]); |
| 1292 } | 1315 } |
| 1293 | 1316 |
| 1294 void test_finalNotInitialized_inConstructor_1() { | 1317 test_finalNotInitialized_inConstructor_1() async { |
| 1295 Source source = addSource(r''' | 1318 Source source = addSource(r''' |
| 1296 class A { | 1319 class A { |
| 1297 final int x; | 1320 final int x; |
| 1298 A() {} | 1321 A() {} |
| 1299 }'''); | 1322 }'''); |
| 1300 assertErrors( | 1323 await assertErrors( |
| 1301 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1]); | 1324 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1]); |
| 1302 verify([source]); | 1325 verify([source]); |
| 1303 } | 1326 } |
| 1304 | 1327 |
| 1305 void test_finalNotInitialized_inConstructor_2() { | 1328 test_finalNotInitialized_inConstructor_2() async { |
| 1306 Source source = addSource(r''' | 1329 Source source = addSource(r''' |
| 1307 class A { | 1330 class A { |
| 1308 final int a; | 1331 final int a; |
| 1309 final int b; | 1332 final int b; |
| 1310 A() {} | 1333 A() {} |
| 1311 }'''); | 1334 }'''); |
| 1312 assertErrors( | 1335 await assertErrors( |
| 1313 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2]); | 1336 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2]); |
| 1314 verify([source]); | 1337 verify([source]); |
| 1315 } | 1338 } |
| 1316 | 1339 |
| 1317 void test_finalNotInitialized_inConstructor_3() { | 1340 test_finalNotInitialized_inConstructor_3() async { |
| 1318 Source source = addSource(r''' | 1341 Source source = addSource(r''' |
| 1319 class A { | 1342 class A { |
| 1320 final int a; | 1343 final int a; |
| 1321 final int b; | 1344 final int b; |
| 1322 final int c; | 1345 final int c; |
| 1323 A() {} | 1346 A() {} |
| 1324 }'''); | 1347 }'''); |
| 1325 assertErrors( | 1348 await assertErrors( |
| 1326 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS]); | 1349 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS]); |
| 1327 verify([source]); | 1350 verify([source]); |
| 1328 } | 1351 } |
| 1329 | 1352 |
| 1330 void test_finalNotInitialized_instanceField_final() { | 1353 test_finalNotInitialized_instanceField_final() async { |
| 1331 Source source = addSource(r''' | 1354 Source source = addSource(r''' |
| 1332 class A { | 1355 class A { |
| 1333 final F; | 1356 final F; |
| 1334 }'''); | 1357 }'''); |
| 1335 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); | 1358 await assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); |
| 1336 verify([source]); | 1359 verify([source]); |
| 1337 } | 1360 } |
| 1338 | 1361 |
| 1339 void test_finalNotInitialized_instanceField_final_static() { | 1362 test_finalNotInitialized_instanceField_final_static() async { |
| 1340 Source source = addSource(r''' | 1363 Source source = addSource(r''' |
| 1341 class A { | 1364 class A { |
| 1342 static final F; | 1365 static final F; |
| 1343 }'''); | 1366 }'''); |
| 1344 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); | 1367 await assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); |
| 1345 verify([source]); | 1368 verify([source]); |
| 1346 } | 1369 } |
| 1347 | 1370 |
| 1348 void test_finalNotInitialized_library_final() { | 1371 test_finalNotInitialized_library_final() async { |
| 1349 Source source = addSource("final F;"); | 1372 Source source = addSource("final F;"); |
| 1350 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); | 1373 await assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); |
| 1351 verify([source]); | 1374 verify([source]); |
| 1352 } | 1375 } |
| 1353 | 1376 |
| 1354 void test_finalNotInitialized_local_final() { | 1377 test_finalNotInitialized_local_final() async { |
| 1355 Source source = addSource(r''' | 1378 Source source = addSource(r''' |
| 1356 f() { | 1379 f() { |
| 1357 final int x; | 1380 final int x; |
| 1358 }'''); | 1381 }'''); |
| 1359 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); | 1382 await assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); |
| 1360 verify([source]); | 1383 verify([source]); |
| 1361 } | 1384 } |
| 1362 | 1385 |
| 1363 void test_functionWithoutCall_direct() { | 1386 test_functionWithoutCall_direct() async { |
| 1364 Source source = addSource(r''' | 1387 Source source = addSource(r''' |
| 1365 class A implements Function { | 1388 class A implements Function { |
| 1366 }'''); | 1389 }'''); |
| 1367 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); | 1390 await assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); |
| 1368 verify([source]); | 1391 verify([source]); |
| 1369 } | 1392 } |
| 1370 | 1393 |
| 1371 void test_functionWithoutCall_indirect_extends() { | 1394 test_functionWithoutCall_indirect_extends() async { |
| 1372 Source source = addSource(r''' | 1395 Source source = addSource(r''' |
| 1373 abstract class A implements Function { | 1396 abstract class A implements Function { |
| 1374 } | 1397 } |
| 1375 class B extends A { | 1398 class B extends A { |
| 1376 }'''); | 1399 }'''); |
| 1377 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); | 1400 await assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); |
| 1378 verify([source]); | 1401 verify([source]); |
| 1379 } | 1402 } |
| 1380 | 1403 |
| 1381 void test_functionWithoutCall_indirect_implements() { | 1404 test_functionWithoutCall_indirect_implements() async { |
| 1382 Source source = addSource(r''' | 1405 Source source = addSource(r''' |
| 1383 abstract class A implements Function { | 1406 abstract class A implements Function { |
| 1384 } | 1407 } |
| 1385 class B implements A { | 1408 class B implements A { |
| 1386 }'''); | 1409 }'''); |
| 1387 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); | 1410 await assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); |
| 1388 verify([source]); | 1411 verify([source]); |
| 1389 } | 1412 } |
| 1390 | 1413 |
| 1391 void test_importDuplicatedLibraryNamed() { | 1414 test_importDuplicatedLibraryNamed() async { |
| 1392 Source source = addSource(r''' | 1415 Source source = addSource(r''' |
| 1393 library test; | 1416 library test; |
| 1394 import 'lib1.dart'; | 1417 import 'lib1.dart'; |
| 1395 import 'lib2.dart';'''); | 1418 import 'lib2.dart';'''); |
| 1396 addNamedSource("/lib1.dart", "library lib;"); | 1419 addNamedSource("/lib1.dart", "library lib;"); |
| 1397 addNamedSource("/lib2.dart", "library lib;"); | 1420 addNamedSource("/lib2.dart", "library lib;"); |
| 1398 assertErrors(source, [ | 1421 await assertErrors(source, [ |
| 1399 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED, | 1422 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED, |
| 1400 HintCode.UNUSED_IMPORT, | 1423 HintCode.UNUSED_IMPORT, |
| 1401 HintCode.UNUSED_IMPORT | 1424 HintCode.UNUSED_IMPORT |
| 1402 ]); | 1425 ]); |
| 1403 verify([source]); | 1426 verify([source]); |
| 1404 } | 1427 } |
| 1405 | 1428 |
| 1406 void test_importOfNonLibrary() { | 1429 test_importOfNonLibrary() async { |
| 1407 resolveWithErrors(<String>[ | 1430 await resolveWithErrors(<String>[ |
| 1408 r''' | 1431 r''' |
| 1409 part of lib; | 1432 part of lib; |
| 1410 class A {}''', | 1433 class A {}''', |
| 1411 r''' | 1434 r''' |
| 1412 library lib; | 1435 library lib; |
| 1413 import 'lib1.dart' deferred as p; | 1436 import 'lib1.dart' deferred as p; |
| 1414 var a = new p.A();''' | 1437 var a = new p.A();''' |
| 1415 ], <ErrorCode>[ | 1438 ], <ErrorCode>[ |
| 1416 StaticWarningCode.IMPORT_OF_NON_LIBRARY | 1439 StaticWarningCode.IMPORT_OF_NON_LIBRARY |
| 1417 ]); | 1440 ]); |
| 1418 } | 1441 } |
| 1419 | 1442 |
| 1420 void test_inconsistentMethodInheritanceGetterAndMethod() { | 1443 test_inconsistentMethodInheritanceGetterAndMethod() async { |
| 1421 Source source = addSource(r''' | 1444 Source source = addSource(r''' |
| 1422 abstract class A { | 1445 abstract class A { |
| 1423 int x(); | 1446 int x(); |
| 1424 } | 1447 } |
| 1425 abstract class B { | 1448 abstract class B { |
| 1426 int get x; | 1449 int get x; |
| 1427 } | 1450 } |
| 1428 class C implements A, B { | 1451 class C implements A, B { |
| 1429 }'''); | 1452 }'''); |
| 1430 assertErrors(source, | 1453 await assertErrors(source, |
| 1431 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); | 1454 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); |
| 1432 verify([source]); | 1455 verify([source]); |
| 1433 } | 1456 } |
| 1434 | 1457 |
| 1435 void test_instanceMethodNameCollidesWithSuperclassStatic_field() { | 1458 test_instanceMethodNameCollidesWithSuperclassStatic_field() async { |
| 1436 Source source = addSource(r''' | 1459 Source source = addSource(r''' |
| 1437 class A { | 1460 class A { |
| 1438 static var n; | 1461 static var n; |
| 1439 } | 1462 } |
| 1440 class B extends A { | 1463 class B extends A { |
| 1441 void n() {} | 1464 void n() {} |
| 1442 }'''); | 1465 }'''); |
| 1443 assertErrors(source, [ | 1466 await assertErrors(source, [ |
| 1444 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1467 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1445 ]); | 1468 ]); |
| 1446 verify([source]); | 1469 verify([source]); |
| 1447 } | 1470 } |
| 1448 | 1471 |
| 1449 void test_instanceMethodNameCollidesWithSuperclassStatic_field2() { | 1472 test_instanceMethodNameCollidesWithSuperclassStatic_field2() async { |
| 1450 Source source = addSource(r''' | 1473 Source source = addSource(r''' |
| 1451 class A { | 1474 class A { |
| 1452 static var n; | 1475 static var n; |
| 1453 } | 1476 } |
| 1454 class B extends A { | 1477 class B extends A { |
| 1455 } | 1478 } |
| 1456 class C extends B { | 1479 class C extends B { |
| 1457 void n() {} | 1480 void n() {} |
| 1458 }'''); | 1481 }'''); |
| 1459 assertErrors(source, [ | 1482 await assertErrors(source, [ |
| 1460 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1483 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1461 ]); | 1484 ]); |
| 1462 verify([source]); | 1485 verify([source]); |
| 1463 } | 1486 } |
| 1464 | 1487 |
| 1465 void test_instanceMethodNameCollidesWithSuperclassStatic_getter() { | 1488 test_instanceMethodNameCollidesWithSuperclassStatic_getter() async { |
| 1466 Source source = addSource(r''' | 1489 Source source = addSource(r''' |
| 1467 class A { | 1490 class A { |
| 1468 static get n {return 0;} | 1491 static get n {return 0;} |
| 1469 } | 1492 } |
| 1470 class B extends A { | 1493 class B extends A { |
| 1471 void n() {} | 1494 void n() {} |
| 1472 }'''); | 1495 }'''); |
| 1473 assertErrors(source, [ | 1496 await assertErrors(source, [ |
| 1474 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1497 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1475 ]); | 1498 ]); |
| 1476 verify([source]); | 1499 verify([source]); |
| 1477 } | 1500 } |
| 1478 | 1501 |
| 1479 void test_instanceMethodNameCollidesWithSuperclassStatic_getter2() { | 1502 test_instanceMethodNameCollidesWithSuperclassStatic_getter2() async { |
| 1480 Source source = addSource(r''' | 1503 Source source = addSource(r''' |
| 1481 class A { | 1504 class A { |
| 1482 static get n {return 0;} | 1505 static get n {return 0;} |
| 1483 } | 1506 } |
| 1484 class B extends A { | 1507 class B extends A { |
| 1485 } | 1508 } |
| 1486 class C extends B { | 1509 class C extends B { |
| 1487 void n() {} | 1510 void n() {} |
| 1488 }'''); | 1511 }'''); |
| 1489 assertErrors(source, [ | 1512 await assertErrors(source, [ |
| 1490 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1513 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1491 ]); | 1514 ]); |
| 1492 verify([source]); | 1515 verify([source]); |
| 1493 } | 1516 } |
| 1494 | 1517 |
| 1495 void test_instanceMethodNameCollidesWithSuperclassStatic_interface() { | 1518 test_instanceMethodNameCollidesWithSuperclassStatic_interface() async { |
| 1496 Source source = addSource(r''' | 1519 Source source = addSource(r''' |
| 1497 class Base { | 1520 class Base { |
| 1498 static foo() {} | 1521 static foo() {} |
| 1499 } | 1522 } |
| 1500 abstract class Ifc { | 1523 abstract class Ifc { |
| 1501 foo(); | 1524 foo(); |
| 1502 } | 1525 } |
| 1503 class C extends Base implements Ifc { | 1526 class C extends Base implements Ifc { |
| 1504 foo() {} | 1527 foo() {} |
| 1505 } | 1528 } |
| 1506 '''); | 1529 '''); |
| 1507 assertErrors(source, [ | 1530 await assertErrors(source, [ |
| 1508 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1531 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1509 ]); | 1532 ]); |
| 1510 verify([source]); | 1533 verify([source]); |
| 1511 } | 1534 } |
| 1512 | 1535 |
| 1513 void test_instanceMethodNameCollidesWithSuperclassStatic_method() { | 1536 test_instanceMethodNameCollidesWithSuperclassStatic_method() async { |
| 1514 Source source = addSource(r''' | 1537 Source source = addSource(r''' |
| 1515 class A { | 1538 class A { |
| 1516 static n () {} | 1539 static n () {} |
| 1517 } | 1540 } |
| 1518 class B extends A { | 1541 class B extends A { |
| 1519 void n() {} | 1542 void n() {} |
| 1520 }'''); | 1543 }'''); |
| 1521 assertErrors(source, [ | 1544 await assertErrors(source, [ |
| 1522 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1545 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1523 ]); | 1546 ]); |
| 1524 verify([source]); | 1547 verify([source]); |
| 1525 } | 1548 } |
| 1526 | 1549 |
| 1527 void test_instanceMethodNameCollidesWithSuperclassStatic_method2() { | 1550 test_instanceMethodNameCollidesWithSuperclassStatic_method2() async { |
| 1528 Source source = addSource(r''' | 1551 Source source = addSource(r''' |
| 1529 class A { | 1552 class A { |
| 1530 static n () {} | 1553 static n () {} |
| 1531 } | 1554 } |
| 1532 class B extends A { | 1555 class B extends A { |
| 1533 } | 1556 } |
| 1534 class C extends B { | 1557 class C extends B { |
| 1535 void n() {} | 1558 void n() {} |
| 1536 }'''); | 1559 }'''); |
| 1537 assertErrors(source, [ | 1560 await assertErrors(source, [ |
| 1538 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1561 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1539 ]); | 1562 ]); |
| 1540 verify([source]); | 1563 verify([source]); |
| 1541 } | 1564 } |
| 1542 | 1565 |
| 1543 void test_instanceMethodNameCollidesWithSuperclassStatic_setter() { | 1566 test_instanceMethodNameCollidesWithSuperclassStatic_setter() async { |
| 1544 Source source = addSource(r''' | 1567 Source source = addSource(r''' |
| 1545 class A { | 1568 class A { |
| 1546 static set n(int x) {} | 1569 static set n(int x) {} |
| 1547 } | 1570 } |
| 1548 class B extends A { | 1571 class B extends A { |
| 1549 void n() {} | 1572 void n() {} |
| 1550 }'''); | 1573 }'''); |
| 1551 assertErrors(source, [ | 1574 await assertErrors(source, [ |
| 1552 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1575 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1553 ]); | 1576 ]); |
| 1554 verify([source]); | 1577 verify([source]); |
| 1555 } | 1578 } |
| 1556 | 1579 |
| 1557 void test_instanceMethodNameCollidesWithSuperclassStatic_setter2() { | 1580 test_instanceMethodNameCollidesWithSuperclassStatic_setter2() async { |
| 1558 Source source = addSource(r''' | 1581 Source source = addSource(r''' |
| 1559 class A { | 1582 class A { |
| 1560 static set n(int x) {} | 1583 static set n(int x) {} |
| 1561 } | 1584 } |
| 1562 class B extends A { | 1585 class B extends A { |
| 1563 } | 1586 } |
| 1564 class C extends B { | 1587 class C extends B { |
| 1565 void n() {} | 1588 void n() {} |
| 1566 }'''); | 1589 }'''); |
| 1567 assertErrors(source, [ | 1590 await assertErrors(source, [ |
| 1568 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 1591 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 1569 ]); | 1592 ]); |
| 1570 verify([source]); | 1593 verify([source]); |
| 1571 } | 1594 } |
| 1572 | 1595 |
| 1573 void test_invalidGetterOverrideReturnType() { | 1596 test_invalidGetterOverrideReturnType() async { |
| 1574 Source source = addSource(r''' | 1597 Source source = addSource(r''' |
| 1575 class A { | 1598 class A { |
| 1576 int get g { return 0; } | 1599 int get g { return 0; } |
| 1577 } | 1600 } |
| 1578 class B extends A { | 1601 class B extends A { |
| 1579 String get g { return 'a'; } | 1602 String get g { return 'a'; } |
| 1580 }'''); | 1603 }'''); |
| 1581 assertErrors( | 1604 await assertErrors( |
| 1582 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); | 1605 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); |
| 1583 verify([source]); | 1606 verify([source]); |
| 1584 } | 1607 } |
| 1585 | 1608 |
| 1586 void test_invalidGetterOverrideReturnType_implicit() { | 1609 test_invalidGetterOverrideReturnType_implicit() async { |
| 1587 Source source = addSource(r''' | 1610 Source source = addSource(r''' |
| 1588 class A { | 1611 class A { |
| 1589 String f; | 1612 String f; |
| 1590 } | 1613 } |
| 1591 class B extends A { | 1614 class B extends A { |
| 1592 int f; | 1615 int f; |
| 1593 }'''); | 1616 }'''); |
| 1594 assertErrors(source, [ | 1617 await assertErrors(source, [ |
| 1595 StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1618 StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
| 1596 StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE | 1619 StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE |
| 1597 ]); | 1620 ]); |
| 1598 verify([source]); | 1621 verify([source]); |
| 1599 } | 1622 } |
| 1600 | 1623 |
| 1601 void test_invalidGetterOverrideReturnType_twoInterfaces() { | 1624 test_invalidGetterOverrideReturnType_twoInterfaces() async { |
| 1602 // test from language/override_inheritance_field_test_11.dart | 1625 // test from language/override_inheritance_field_test_11.dart |
| 1603 Source source = addSource(r''' | 1626 Source source = addSource(r''' |
| 1604 abstract class I { | 1627 abstract class I { |
| 1605 int get getter => null; | 1628 int get getter => null; |
| 1606 } | 1629 } |
| 1607 abstract class J { | 1630 abstract class J { |
| 1608 num get getter => null; | 1631 num get getter => null; |
| 1609 } | 1632 } |
| 1610 abstract class A implements I, J {} | 1633 abstract class A implements I, J {} |
| 1611 class B extends A { | 1634 class B extends A { |
| 1612 String get getter => null; | 1635 String get getter => null; |
| 1613 }'''); | 1636 }'''); |
| 1614 assertErrors( | 1637 await assertErrors( |
| 1615 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); | 1638 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); |
| 1616 verify([source]); | 1639 verify([source]); |
| 1617 } | 1640 } |
| 1618 | 1641 |
| 1619 void test_invalidGetterOverrideReturnType_twoInterfaces_conflicting() { | 1642 test_invalidGetterOverrideReturnType_twoInterfaces_conflicting() async { |
| 1620 Source source = addSource(r''' | 1643 Source source = addSource(r''' |
| 1621 abstract class I<U> { | 1644 abstract class I<U> { |
| 1622 U get g => null; | 1645 U get g => null; |
| 1623 } | 1646 } |
| 1624 abstract class J<V> { | 1647 abstract class J<V> { |
| 1625 V get g => null; | 1648 V get g => null; |
| 1626 } | 1649 } |
| 1627 class B implements I<int>, J<String> { | 1650 class B implements I<int>, J<String> { |
| 1628 double get g => null; | 1651 double get g => null; |
| 1629 }'''); | 1652 }'''); |
| 1630 assertErrors( | 1653 await assertErrors( |
| 1631 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); | 1654 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); |
| 1632 verify([source]); | 1655 verify([source]); |
| 1633 } | 1656 } |
| 1634 | 1657 |
| 1635 void test_invalidMethodOverrideNamedParamType() { | 1658 test_invalidMethodOverrideNamedParamType() async { |
| 1636 Source source = addSource(r''' | 1659 Source source = addSource(r''' |
| 1637 class A { | 1660 class A { |
| 1638 m({int a}) {} | 1661 m({int a}) {} |
| 1639 } | 1662 } |
| 1640 class B implements A { | 1663 class B implements A { |
| 1641 m({String a}) {} | 1664 m({String a}) {} |
| 1642 }'''); | 1665 }'''); |
| 1643 assertErrors( | 1666 await assertErrors( |
| 1644 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE]); | 1667 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE]); |
| 1645 verify([source]); | 1668 verify([source]); |
| 1646 } | 1669 } |
| 1647 | 1670 |
| 1648 void test_invalidMethodOverrideNormalParamType_interface() { | 1671 test_invalidMethodOverrideNormalParamType_interface() async { |
| 1649 Source source = addSource(r''' | 1672 Source source = addSource(r''' |
| 1650 class A { | 1673 class A { |
| 1651 m(int a) {} | 1674 m(int a) {} |
| 1652 } | 1675 } |
| 1653 class B implements A { | 1676 class B implements A { |
| 1654 m(String a) {} | 1677 m(String a) {} |
| 1655 }'''); | 1678 }'''); |
| 1656 assertErrors( | 1679 await assertErrors( |
| 1657 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); | 1680 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 1658 verify([source]); | 1681 verify([source]); |
| 1659 } | 1682 } |
| 1660 | 1683 |
| 1661 void test_invalidMethodOverrideNormalParamType_superclass() { | 1684 test_invalidMethodOverrideNormalParamType_superclass() async { |
| 1662 Source source = addSource(r''' | 1685 Source source = addSource(r''' |
| 1663 class A { | 1686 class A { |
| 1664 m(int a) {} | 1687 m(int a) {} |
| 1665 } | 1688 } |
| 1666 class B extends A { | 1689 class B extends A { |
| 1667 m(String a) {} | 1690 m(String a) {} |
| 1668 }'''); | 1691 }'''); |
| 1669 assertErrors( | 1692 await assertErrors( |
| 1670 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); | 1693 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 1671 verify([source]); | 1694 verify([source]); |
| 1672 } | 1695 } |
| 1673 | 1696 |
| 1674 void test_invalidMethodOverrideNormalParamType_superclass_interface() { | 1697 test_invalidMethodOverrideNormalParamType_superclass_interface() async { |
| 1675 Source source = addSource(r''' | 1698 Source source = addSource(r''' |
| 1676 abstract class I<U> { | 1699 abstract class I<U> { |
| 1677 m(U u) => null; | 1700 m(U u) => null; |
| 1678 } | 1701 } |
| 1679 abstract class J<V> { | 1702 abstract class J<V> { |
| 1680 m(V v) => null; | 1703 m(V v) => null; |
| 1681 } | 1704 } |
| 1682 class B extends I<int> implements J<String> { | 1705 class B extends I<int> implements J<String> { |
| 1683 m(double d) {} | 1706 m(double d) {} |
| 1684 }'''); | 1707 }'''); |
| 1685 assertErrors( | 1708 await assertErrors( |
| 1686 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); | 1709 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 1687 verify([source]); | 1710 verify([source]); |
| 1688 } | 1711 } |
| 1689 | 1712 |
| 1690 void test_invalidMethodOverrideNormalParamType_twoInterfaces() { | 1713 test_invalidMethodOverrideNormalParamType_twoInterfaces() async { |
| 1691 Source source = addSource(r''' | 1714 Source source = addSource(r''' |
| 1692 abstract class I { | 1715 abstract class I { |
| 1693 m(int n); | 1716 m(int n); |
| 1694 } | 1717 } |
| 1695 abstract class J { | 1718 abstract class J { |
| 1696 m(num n); | 1719 m(num n); |
| 1697 } | 1720 } |
| 1698 abstract class A implements I, J {} | 1721 abstract class A implements I, J {} |
| 1699 class B extends A { | 1722 class B extends A { |
| 1700 m(String n) {} | 1723 m(String n) {} |
| 1701 }'''); | 1724 }'''); |
| 1702 assertErrors( | 1725 await assertErrors( |
| 1703 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); | 1726 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 1704 verify([source]); | 1727 verify([source]); |
| 1705 } | 1728 } |
| 1706 | 1729 |
| 1707 void test_invalidMethodOverrideNormalParamType_twoInterfaces_conflicting() { | 1730 test_invalidMethodOverrideNormalParamType_twoInterfaces_conflicting() async { |
| 1708 // language/override_inheritance_generic_test/08 | 1731 // language/override_inheritance_generic_test/08 |
| 1709 Source source = addSource(r''' | 1732 Source source = addSource(r''' |
| 1710 abstract class I<U> { | 1733 abstract class I<U> { |
| 1711 m(U u) => null; | 1734 m(U u) => null; |
| 1712 } | 1735 } |
| 1713 abstract class J<V> { | 1736 abstract class J<V> { |
| 1714 m(V v) => null; | 1737 m(V v) => null; |
| 1715 } | 1738 } |
| 1716 class B implements I<int>, J<String> { | 1739 class B implements I<int>, J<String> { |
| 1717 m(double d) {} | 1740 m(double d) {} |
| 1718 }'''); | 1741 }'''); |
| 1719 assertErrors( | 1742 await assertErrors( |
| 1720 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); | 1743 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 1721 verify([source]); | 1744 verify([source]); |
| 1722 } | 1745 } |
| 1723 | 1746 |
| 1724 void test_invalidMethodOverrideOptionalParamType() { | 1747 test_invalidMethodOverrideOptionalParamType() async { |
| 1725 Source source = addSource(r''' | 1748 Source source = addSource(r''' |
| 1726 class A { | 1749 class A { |
| 1727 m([int a]) {} | 1750 m([int a]) {} |
| 1728 } | 1751 } |
| 1729 class B implements A { | 1752 class B implements A { |
| 1730 m([String a]) {} | 1753 m([String a]) {} |
| 1731 }'''); | 1754 }'''); |
| 1732 assertErrors(source, | 1755 await assertErrors(source, |
| 1733 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]); | 1756 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]); |
| 1734 verify([source]); | 1757 verify([source]); |
| 1735 } | 1758 } |
| 1736 | 1759 |
| 1737 void test_invalidMethodOverrideOptionalParamType_twoInterfaces() { | 1760 test_invalidMethodOverrideOptionalParamType_twoInterfaces() async { |
| 1738 Source source = addSource(r''' | 1761 Source source = addSource(r''' |
| 1739 abstract class I { | 1762 abstract class I { |
| 1740 m([int n]); | 1763 m([int n]); |
| 1741 } | 1764 } |
| 1742 abstract class J { | 1765 abstract class J { |
| 1743 m([num n]); | 1766 m([num n]); |
| 1744 } | 1767 } |
| 1745 abstract class A implements I, J {} | 1768 abstract class A implements I, J {} |
| 1746 class B extends A { | 1769 class B extends A { |
| 1747 m([String n]) {} | 1770 m([String n]) {} |
| 1748 }'''); | 1771 }'''); |
| 1749 assertErrors(source, | 1772 await assertErrors(source, |
| 1750 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]); | 1773 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]); |
| 1751 verify([source]); | 1774 verify([source]); |
| 1752 } | 1775 } |
| 1753 | 1776 |
| 1754 void test_invalidMethodOverrideReturnType_interface() { | 1777 test_invalidMethodOverrideReturnType_interface() async { |
| 1755 Source source = addSource(r''' | 1778 Source source = addSource(r''' |
| 1756 class A { | 1779 class A { |
| 1757 int m() { return 0; } | 1780 int m() { return 0; } |
| 1758 } | 1781 } |
| 1759 class B implements A { | 1782 class B implements A { |
| 1760 String m() { return 'a'; } | 1783 String m() { return 'a'; } |
| 1761 }'''); | 1784 }'''); |
| 1762 assertErrors( | 1785 await assertErrors( |
| 1763 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1786 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1764 verify([source]); | 1787 verify([source]); |
| 1765 } | 1788 } |
| 1766 | 1789 |
| 1767 void test_invalidMethodOverrideReturnType_interface_grandparent() { | 1790 test_invalidMethodOverrideReturnType_interface_grandparent() async { |
| 1768 Source source = addSource(r''' | 1791 Source source = addSource(r''' |
| 1769 abstract class A { | 1792 abstract class A { |
| 1770 int m(); | 1793 int m(); |
| 1771 } | 1794 } |
| 1772 abstract class B implements A { | 1795 abstract class B implements A { |
| 1773 } | 1796 } |
| 1774 class C implements B { | 1797 class C implements B { |
| 1775 String m() { return 'a'; } | 1798 String m() { return 'a'; } |
| 1776 }'''); | 1799 }'''); |
| 1777 assertErrors( | 1800 await assertErrors( |
| 1778 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1801 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1779 verify([source]); | 1802 verify([source]); |
| 1780 } | 1803 } |
| 1781 | 1804 |
| 1782 void test_invalidMethodOverrideReturnType_mixin() { | 1805 test_invalidMethodOverrideReturnType_mixin() async { |
| 1783 Source source = addSource(r''' | 1806 Source source = addSource(r''' |
| 1784 class A { | 1807 class A { |
| 1785 int m() { return 0; } | 1808 int m() { return 0; } |
| 1786 } | 1809 } |
| 1787 class B extends Object with A { | 1810 class B extends Object with A { |
| 1788 String m() { return 'a'; } | 1811 String m() { return 'a'; } |
| 1789 }'''); | 1812 }'''); |
| 1790 assertErrors( | 1813 await assertErrors( |
| 1791 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1814 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1792 verify([source]); | 1815 verify([source]); |
| 1793 } | 1816 } |
| 1794 | 1817 |
| 1795 void test_invalidMethodOverrideReturnType_superclass() { | 1818 test_invalidMethodOverrideReturnType_superclass() async { |
| 1796 Source source = addSource(r''' | 1819 Source source = addSource(r''' |
| 1797 class A { | 1820 class A { |
| 1798 int m() { return 0; } | 1821 int m() { return 0; } |
| 1799 } | 1822 } |
| 1800 class B extends A { | 1823 class B extends A { |
| 1801 String m() { return 'a'; } | 1824 String m() { return 'a'; } |
| 1802 }'''); | 1825 }'''); |
| 1803 assertErrors( | 1826 await assertErrors( |
| 1804 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1827 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1805 verify([source]); | 1828 verify([source]); |
| 1806 } | 1829 } |
| 1807 | 1830 |
| 1808 void test_invalidMethodOverrideReturnType_superclass_grandparent() { | 1831 test_invalidMethodOverrideReturnType_superclass_grandparent() async { |
| 1809 Source source = addSource(r''' | 1832 Source source = addSource(r''' |
| 1810 class A { | 1833 class A { |
| 1811 int m() { return 0; } | 1834 int m() { return 0; } |
| 1812 } | 1835 } |
| 1813 class B extends A { | 1836 class B extends A { |
| 1814 } | 1837 } |
| 1815 class C extends B { | 1838 class C extends B { |
| 1816 String m() { return 'a'; } | 1839 String m() { return 'a'; } |
| 1817 }'''); | 1840 }'''); |
| 1818 assertErrors( | 1841 await assertErrors( |
| 1819 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1842 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1820 verify([source]); | 1843 verify([source]); |
| 1821 } | 1844 } |
| 1822 | 1845 |
| 1823 void test_invalidMethodOverrideReturnType_twoInterfaces() { | 1846 test_invalidMethodOverrideReturnType_twoInterfaces() async { |
| 1824 Source source = addSource(r''' | 1847 Source source = addSource(r''' |
| 1825 abstract class I { | 1848 abstract class I { |
| 1826 int m(); | 1849 int m(); |
| 1827 } | 1850 } |
| 1828 abstract class J { | 1851 abstract class J { |
| 1829 num m(); | 1852 num m(); |
| 1830 } | 1853 } |
| 1831 abstract class A implements I, J {} | 1854 abstract class A implements I, J {} |
| 1832 class B extends A { | 1855 class B extends A { |
| 1833 String m() => ''; | 1856 String m() => ''; |
| 1834 }'''); | 1857 }'''); |
| 1835 assertErrors( | 1858 await assertErrors( |
| 1836 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1859 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1837 verify([source]); | 1860 verify([source]); |
| 1838 } | 1861 } |
| 1839 | 1862 |
| 1840 void test_invalidMethodOverrideReturnType_void() { | 1863 test_invalidMethodOverrideReturnType_void() async { |
| 1841 Source source = addSource(r''' | 1864 Source source = addSource(r''' |
| 1842 class A { | 1865 class A { |
| 1843 int m() { return 0; } | 1866 int m() { return 0; } |
| 1844 } | 1867 } |
| 1845 class B extends A { | 1868 class B extends A { |
| 1846 void m() {} | 1869 void m() {} |
| 1847 }'''); | 1870 }'''); |
| 1848 assertErrors( | 1871 await assertErrors( |
| 1849 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); | 1872 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); |
| 1850 verify([source]); | 1873 verify([source]); |
| 1851 } | 1874 } |
| 1852 | 1875 |
| 1853 void test_invalidOverride_defaultOverridesNonDefault() { | 1876 test_invalidOverride_defaultOverridesNonDefault() async { |
| 1854 // If the base class provided an explicit value for a default parameter, | 1877 // If the base class provided an explicit value for a default parameter, |
| 1855 // then it is a static warning for the derived class to provide a different | 1878 // then it is a static warning for the derived class to provide a different |
| 1856 // value, even if implicitly. | 1879 // value, even if implicitly. |
| 1857 Source source = addSource(r''' | 1880 Source source = addSource(r''' |
| 1858 class A { | 1881 class A { |
| 1859 foo([x = 1]) {} | 1882 foo([x = 1]) {} |
| 1860 } | 1883 } |
| 1861 class B extends A { | 1884 class B extends A { |
| 1862 foo([x]) {} | 1885 foo([x]) {} |
| 1863 } | 1886 } |
| 1864 '''); | 1887 '''); |
| 1865 assertErrors(source, [ | 1888 await assertErrors(source, [ |
| 1866 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL | 1889 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL |
| 1867 ]); | 1890 ]); |
| 1868 verify([source]); | 1891 verify([source]); |
| 1869 } | 1892 } |
| 1870 | 1893 |
| 1871 void test_invalidOverride_defaultOverridesNonDefault_named() { | 1894 test_invalidOverride_defaultOverridesNonDefault_named() async { |
| 1872 // If the base class provided an explicit value for a default parameter, | 1895 // If the base class provided an explicit value for a default parameter, |
| 1873 // then it is a static warning for the derived class to provide a different | 1896 // then it is a static warning for the derived class to provide a different |
| 1874 // value, even if implicitly. | 1897 // value, even if implicitly. |
| 1875 Source source = addSource(r''' | 1898 Source source = addSource(r''' |
| 1876 class A { | 1899 class A { |
| 1877 foo({x: 1}) {} | 1900 foo({x: 1}) {} |
| 1878 } | 1901 } |
| 1879 class B extends A { | 1902 class B extends A { |
| 1880 foo({x}) {} | 1903 foo({x}) {} |
| 1881 } | 1904 } |
| 1882 '''); | 1905 '''); |
| 1883 assertErrors(source, | 1906 await assertErrors(source, |
| 1884 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]); | 1907 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]); |
| 1885 verify([source]); | 1908 verify([source]); |
| 1886 } | 1909 } |
| 1887 | 1910 |
| 1888 void test_invalidOverride_defaultOverridesNonDefaultNull() { | 1911 test_invalidOverride_defaultOverridesNonDefaultNull() async { |
| 1889 // If the base class provided an explicit null value for a default | 1912 // If the base class provided an explicit null value for a default |
| 1890 // parameter, then it is ok for the derived class to let the default value | 1913 // parameter, then it is ok for the derived class to let the default value |
| 1891 // be implicit, because the implicit default value of null matches the | 1914 // be implicit, because the implicit default value of null matches the |
| 1892 // explicit default value of null. | 1915 // explicit default value of null. |
| 1893 Source source = addSource(r''' | 1916 Source source = addSource(r''' |
| 1894 class A { | 1917 class A { |
| 1895 foo([x = null]) {} | 1918 foo([x = null]) {} |
| 1896 } | 1919 } |
| 1897 class B extends A { | 1920 class B extends A { |
| 1898 foo([x]) {} | 1921 foo([x]) {} |
| 1899 } | 1922 } |
| 1900 '''); | 1923 '''); |
| 1901 assertNoErrors(source); | 1924 await assertNoErrors(source); |
| 1902 verify([source]); | 1925 verify([source]); |
| 1903 } | 1926 } |
| 1904 | 1927 |
| 1905 void test_invalidOverride_defaultOverridesNonDefaultNull_named() { | 1928 test_invalidOverride_defaultOverridesNonDefaultNull_named() async { |
| 1906 // If the base class provided an explicit null value for a default | 1929 // If the base class provided an explicit null value for a default |
| 1907 // parameter, then it is ok for the derived class to let the default value | 1930 // parameter, then it is ok for the derived class to let the default value |
| 1908 // be implicit, because the implicit default value of null matches the | 1931 // be implicit, because the implicit default value of null matches the |
| 1909 // explicit default value of null. | 1932 // explicit default value of null. |
| 1910 Source source = addSource(r''' | 1933 Source source = addSource(r''' |
| 1911 class A { | 1934 class A { |
| 1912 foo({x: null}) {} | 1935 foo({x: null}) {} |
| 1913 } | 1936 } |
| 1914 class B extends A { | 1937 class B extends A { |
| 1915 foo({x}) {} | 1938 foo({x}) {} |
| 1916 } | 1939 } |
| 1917 '''); | 1940 '''); |
| 1918 assertNoErrors(source); | 1941 await assertNoErrors(source); |
| 1919 verify([source]); | 1942 verify([source]); |
| 1920 } | 1943 } |
| 1921 | 1944 |
| 1922 void test_invalidOverride_nonDefaultOverridesDefault() { | 1945 test_invalidOverride_nonDefaultOverridesDefault() async { |
| 1923 // If the base class lets the default parameter be implicit, then it is ok | 1946 // If the base class lets the default parameter be implicit, then it is ok |
| 1924 // for the derived class to provide an explicit default value, even if it's | 1947 // for the derived class to provide an explicit default value, even if it's |
| 1925 // not null. | 1948 // not null. |
| 1926 Source source = addSource(r''' | 1949 Source source = addSource(r''' |
| 1927 class A { | 1950 class A { |
| 1928 foo([x]) {} | 1951 foo([x]) {} |
| 1929 } | 1952 } |
| 1930 class B extends A { | 1953 class B extends A { |
| 1931 foo([x = 1]) {} | 1954 foo([x = 1]) {} |
| 1932 } | 1955 } |
| 1933 '''); | 1956 '''); |
| 1934 assertNoErrors(source); | 1957 await assertNoErrors(source); |
| 1935 verify([source]); | 1958 verify([source]); |
| 1936 } | 1959 } |
| 1937 | 1960 |
| 1938 void test_invalidOverride_nonDefaultOverridesDefault_named() { | 1961 test_invalidOverride_nonDefaultOverridesDefault_named() async { |
| 1939 // If the base class lets the default parameter be implicit, then it is ok | 1962 // If the base class lets the default parameter be implicit, then it is ok |
| 1940 // for the derived class to provide an explicit default value, even if it's | 1963 // for the derived class to provide an explicit default value, even if it's |
| 1941 // not null. | 1964 // not null. |
| 1942 Source source = addSource(r''' | 1965 Source source = addSource(r''' |
| 1943 class A { | 1966 class A { |
| 1944 foo({x}) {} | 1967 foo({x}) {} |
| 1945 } | 1968 } |
| 1946 class B extends A { | 1969 class B extends A { |
| 1947 foo({x: 1}) {} | 1970 foo({x: 1}) {} |
| 1948 } | 1971 } |
| 1949 '''); | 1972 '''); |
| 1950 assertNoErrors(source); | 1973 await assertNoErrors(source); |
| 1951 verify([source]); | 1974 verify([source]); |
| 1952 } | 1975 } |
| 1953 | 1976 |
| 1954 void test_invalidOverrideDifferentDefaultValues_named() { | 1977 test_invalidOverrideDifferentDefaultValues_named() async { |
| 1955 Source source = addSource(r''' | 1978 Source source = addSource(r''' |
| 1956 class A { | 1979 class A { |
| 1957 m({int p : 0}) {} | 1980 m({int p : 0}) {} |
| 1958 } | 1981 } |
| 1959 class B extends A { | 1982 class B extends A { |
| 1960 m({int p : 1}) {} | 1983 m({int p : 1}) {} |
| 1961 }'''); | 1984 }'''); |
| 1962 assertErrors(source, | 1985 await assertErrors(source, |
| 1963 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]); | 1986 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]); |
| 1964 verify([source]); | 1987 verify([source]); |
| 1965 } | 1988 } |
| 1966 | 1989 |
| 1967 void test_invalidOverrideDifferentDefaultValues_positional() { | 1990 test_invalidOverrideDifferentDefaultValues_positional() async { |
| 1968 Source source = addSource(r''' | 1991 Source source = addSource(r''' |
| 1969 class A { | 1992 class A { |
| 1970 m([int p = 0]) {} | 1993 m([int p = 0]) {} |
| 1971 } | 1994 } |
| 1972 class B extends A { | 1995 class B extends A { |
| 1973 m([int p = 1]) {} | 1996 m([int p = 1]) {} |
| 1974 }'''); | 1997 }'''); |
| 1975 assertErrors(source, [ | 1998 await assertErrors(source, [ |
| 1976 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL | 1999 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL |
| 1977 ]); | 2000 ]); |
| 1978 verify([source]); | 2001 verify([source]); |
| 1979 } | 2002 } |
| 1980 | 2003 |
| 1981 void test_invalidOverrideNamed_fewerNamedParameters() { | 2004 test_invalidOverrideNamed_fewerNamedParameters() async { |
| 1982 Source source = addSource(r''' | 2005 Source source = addSource(r''' |
| 1983 class A { | 2006 class A { |
| 1984 m({a, b}) {} | 2007 m({a, b}) {} |
| 1985 } | 2008 } |
| 1986 class B extends A { | 2009 class B extends A { |
| 1987 m({a}) {} | 2010 m({a}) {} |
| 1988 }'''); | 2011 }'''); |
| 1989 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]); | 2012 await assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]); |
| 1990 verify([source]); | 2013 verify([source]); |
| 1991 } | 2014 } |
| 1992 | 2015 |
| 1993 void test_invalidOverrideNamed_missingNamedParameter() { | 2016 test_invalidOverrideNamed_missingNamedParameter() async { |
| 1994 Source source = addSource(r''' | 2017 Source source = addSource(r''' |
| 1995 class A { | 2018 class A { |
| 1996 m({a, b}) {} | 2019 m({a, b}) {} |
| 1997 } | 2020 } |
| 1998 class B extends A { | 2021 class B extends A { |
| 1999 m({a, c}) {} | 2022 m({a, c}) {} |
| 2000 }'''); | 2023 }'''); |
| 2001 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]); | 2024 await assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]); |
| 2002 verify([source]); | 2025 verify([source]); |
| 2003 } | 2026 } |
| 2004 | 2027 |
| 2005 void test_invalidOverridePositional_optional() { | 2028 test_invalidOverridePositional_optional() async { |
| 2006 Source source = addSource(r''' | 2029 Source source = addSource(r''' |
| 2007 class A { | 2030 class A { |
| 2008 m([a, b]) {} | 2031 m([a, b]) {} |
| 2009 } | 2032 } |
| 2010 class B extends A { | 2033 class B extends A { |
| 2011 m([a]) {} | 2034 m([a]) {} |
| 2012 }'''); | 2035 }'''); |
| 2013 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); | 2036 await assertErrors( |
| 2037 source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); |
| 2014 verify([source]); | 2038 verify([source]); |
| 2015 } | 2039 } |
| 2016 | 2040 |
| 2017 void test_invalidOverridePositional_optionalAndRequired() { | 2041 test_invalidOverridePositional_optionalAndRequired() async { |
| 2018 Source source = addSource(r''' | 2042 Source source = addSource(r''' |
| 2019 class A { | 2043 class A { |
| 2020 m(a, b, [c, d]) {} | 2044 m(a, b, [c, d]) {} |
| 2021 } | 2045 } |
| 2022 class B extends A { | 2046 class B extends A { |
| 2023 m(a, b, [c]) {} | 2047 m(a, b, [c]) {} |
| 2024 }'''); | 2048 }'''); |
| 2025 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); | 2049 await assertErrors( |
| 2050 source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); |
| 2026 verify([source]); | 2051 verify([source]); |
| 2027 } | 2052 } |
| 2028 | 2053 |
| 2029 void test_invalidOverridePositional_optionalAndRequired2() { | 2054 test_invalidOverridePositional_optionalAndRequired2() async { |
| 2030 Source source = addSource(r''' | 2055 Source source = addSource(r''' |
| 2031 class A { | 2056 class A { |
| 2032 m(a, b, [c, d]) {} | 2057 m(a, b, [c, d]) {} |
| 2033 } | 2058 } |
| 2034 class B extends A { | 2059 class B extends A { |
| 2035 m(a, [c, d]) {} | 2060 m(a, [c, d]) {} |
| 2036 }'''); | 2061 }'''); |
| 2037 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); | 2062 await assertErrors( |
| 2063 source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); |
| 2038 verify([source]); | 2064 verify([source]); |
| 2039 } | 2065 } |
| 2040 | 2066 |
| 2041 void test_invalidOverrideRequired() { | 2067 test_invalidOverrideRequired() async { |
| 2042 Source source = addSource(r''' | 2068 Source source = addSource(r''' |
| 2043 class A { | 2069 class A { |
| 2044 m(a) {} | 2070 m(a) {} |
| 2045 } | 2071 } |
| 2046 class B extends A { | 2072 class B extends A { |
| 2047 m(a, b) {} | 2073 m(a, b) {} |
| 2048 }'''); | 2074 }'''); |
| 2049 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_REQUIRED]); | 2075 await assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_REQUIRED]); |
| 2050 verify([source]); | 2076 verify([source]); |
| 2051 } | 2077 } |
| 2052 | 2078 |
| 2053 void test_invalidSetterOverrideNormalParamType() { | 2079 test_invalidSetterOverrideNormalParamType() async { |
| 2054 Source source = addSource(r''' | 2080 Source source = addSource(r''' |
| 2055 class A { | 2081 class A { |
| 2056 void set s(int v) {} | 2082 void set s(int v) {} |
| 2057 } | 2083 } |
| 2058 class B extends A { | 2084 class B extends A { |
| 2059 void set s(String v) {} | 2085 void set s(String v) {} |
| 2060 }'''); | 2086 }'''); |
| 2061 assertErrors( | 2087 await assertErrors( |
| 2062 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); | 2088 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 2063 verify([source]); | 2089 verify([source]); |
| 2064 } | 2090 } |
| 2065 | 2091 |
| 2066 void test_invalidSetterOverrideNormalParamType_superclass_interface() { | 2092 test_invalidSetterOverrideNormalParamType_superclass_interface() async { |
| 2067 Source source = addSource(r''' | 2093 Source source = addSource(r''' |
| 2068 abstract class I { | 2094 abstract class I { |
| 2069 set setter14(int _) => null; | 2095 set setter14(int _) => null; |
| 2070 } | 2096 } |
| 2071 abstract class J { | 2097 abstract class J { |
| 2072 set setter14(num _) => null; | 2098 set setter14(num _) => null; |
| 2073 } | 2099 } |
| 2074 abstract class A extends I implements J {} | 2100 abstract class A extends I implements J {} |
| 2075 class B extends A { | 2101 class B extends A { |
| 2076 set setter14(String _) => null; | 2102 set setter14(String _) => null; |
| 2077 }'''); | 2103 }'''); |
| 2078 assertErrors( | 2104 await assertErrors( |
| 2079 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); | 2105 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 2080 verify([source]); | 2106 verify([source]); |
| 2081 } | 2107 } |
| 2082 | 2108 |
| 2083 void test_invalidSetterOverrideNormalParamType_twoInterfaces() { | 2109 test_invalidSetterOverrideNormalParamType_twoInterfaces() async { |
| 2084 // test from language/override_inheritance_field_test_34.dart | 2110 // test from language/override_inheritance_field_test_34.dart |
| 2085 Source source = addSource(r''' | 2111 Source source = addSource(r''' |
| 2086 abstract class I { | 2112 abstract class I { |
| 2087 set setter14(int _) => null; | 2113 set setter14(int _) => null; |
| 2088 } | 2114 } |
| 2089 abstract class J { | 2115 abstract class J { |
| 2090 set setter14(num _) => null; | 2116 set setter14(num _) => null; |
| 2091 } | 2117 } |
| 2092 abstract class A implements I, J {} | 2118 abstract class A implements I, J {} |
| 2093 class B extends A { | 2119 class B extends A { |
| 2094 set setter14(String _) => null; | 2120 set setter14(String _) => null; |
| 2095 }'''); | 2121 }'''); |
| 2096 assertErrors( | 2122 await assertErrors( |
| 2097 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); | 2123 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 2098 verify([source]); | 2124 verify([source]); |
| 2099 } | 2125 } |
| 2100 | 2126 |
| 2101 void test_invalidSetterOverrideNormalParamType_twoInterfaces_conflicting() { | 2127 test_invalidSetterOverrideNormalParamType_twoInterfaces_conflicting() async { |
| 2102 Source source = addSource(r''' | 2128 Source source = addSource(r''' |
| 2103 abstract class I<U> { | 2129 abstract class I<U> { |
| 2104 set s(U u) {} | 2130 set s(U u) {} |
| 2105 } | 2131 } |
| 2106 abstract class J<V> { | 2132 abstract class J<V> { |
| 2107 set s(V v) {} | 2133 set s(V v) {} |
| 2108 } | 2134 } |
| 2109 class B implements I<int>, J<String> { | 2135 class B implements I<int>, J<String> { |
| 2110 set s(double d) {} | 2136 set s(double d) {} |
| 2111 }'''); | 2137 }'''); |
| 2112 assertErrors( | 2138 await assertErrors( |
| 2113 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); | 2139 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); |
| 2114 verify([source]); | 2140 verify([source]); |
| 2115 } | 2141 } |
| 2116 | 2142 |
| 2117 void test_listElementTypeNotAssignable() { | 2143 test_listElementTypeNotAssignable() async { |
| 2118 Source source = addSource("var v = <String> [42];"); | 2144 Source source = addSource("var v = <String> [42];"); |
| 2119 assertErrors(source, [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]); | 2145 await assertErrors( |
| 2146 source, [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]); |
| 2120 verify([source]); | 2147 verify([source]); |
| 2121 } | 2148 } |
| 2122 | 2149 |
| 2123 void test_mapKeyTypeNotAssignable() { | 2150 test_mapKeyTypeNotAssignable() async { |
| 2124 Source source = addSource("var v = <String, int > {1 : 2};"); | 2151 Source source = addSource("var v = <String, int > {1 : 2};"); |
| 2125 assertErrors(source, [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE]); | 2152 await assertErrors( |
| 2153 source, [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE]); |
| 2126 verify([source]); | 2154 verify([source]); |
| 2127 } | 2155 } |
| 2128 | 2156 |
| 2129 void test_mapValueTypeNotAssignable() { | 2157 test_mapValueTypeNotAssignable() async { |
| 2130 Source source = addSource("var v = <String, String> {'a' : 2};"); | 2158 Source source = addSource("var v = <String, String> {'a' : 2};"); |
| 2131 assertErrors(source, [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]); | 2159 await assertErrors( |
| 2160 source, [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]); |
| 2132 verify([source]); | 2161 verify([source]); |
| 2133 } | 2162 } |
| 2134 | 2163 |
| 2135 void test_mismatchedAccessorTypes_class() { | 2164 test_mismatchedAccessorTypes_class() async { |
| 2136 Source source = addSource(r''' | 2165 Source source = addSource(r''' |
| 2137 class A { | 2166 class A { |
| 2138 int get g { return 0; } | 2167 int get g { return 0; } |
| 2139 set g(String v) {} | 2168 set g(String v) {} |
| 2140 }'''); | 2169 }'''); |
| 2141 assertErrors( | 2170 await assertErrors( |
| 2142 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); | 2171 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); |
| 2143 verify([source]); | 2172 verify([source]); |
| 2144 } | 2173 } |
| 2145 | 2174 |
| 2146 void test_mismatchedAccessorTypes_getterAndSuperSetter() { | 2175 test_mismatchedAccessorTypes_getterAndSuperSetter() async { |
| 2147 Source source = addSource(r''' | 2176 Source source = addSource(r''' |
| 2148 class A { | 2177 class A { |
| 2149 int get g { return 0; } | 2178 int get g { return 0; } |
| 2150 } | 2179 } |
| 2151 class B extends A { | 2180 class B extends A { |
| 2152 set g(String v) {} | 2181 set g(String v) {} |
| 2153 }'''); | 2182 }'''); |
| 2154 assertErrors(source, | 2183 await assertErrors(source, |
| 2155 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]); | 2184 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]); |
| 2156 verify([source]); | 2185 verify([source]); |
| 2157 } | 2186 } |
| 2158 | 2187 |
| 2159 void test_mismatchedAccessorTypes_setterAndSuperGetter() { | 2188 test_mismatchedAccessorTypes_setterAndSuperGetter() async { |
| 2160 Source source = addSource(r''' | 2189 Source source = addSource(r''' |
| 2161 class A { | 2190 class A { |
| 2162 set g(int v) {} | 2191 set g(int v) {} |
| 2163 } | 2192 } |
| 2164 class B extends A { | 2193 class B extends A { |
| 2165 String get g { return ''; } | 2194 String get g { return ''; } |
| 2166 }'''); | 2195 }'''); |
| 2167 assertErrors(source, | 2196 await assertErrors(source, |
| 2168 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]); | 2197 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]); |
| 2169 verify([source]); | 2198 verify([source]); |
| 2170 } | 2199 } |
| 2171 | 2200 |
| 2172 void test_mismatchedAccessorTypes_topLevel() { | 2201 test_mismatchedAccessorTypes_topLevel() async { |
| 2173 Source source = addSource(r''' | 2202 Source source = addSource(r''' |
| 2174 int get g { return 0; } | 2203 int get g { return 0; } |
| 2175 set g(String v) {}'''); | 2204 set g(String v) {}'''); |
| 2176 assertErrors( | 2205 await assertErrors( |
| 2177 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); | 2206 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); |
| 2178 verify([source]); | 2207 verify([source]); |
| 2179 } | 2208 } |
| 2180 | 2209 |
| 2181 void test_missingEnumConstantInSwitch() { | 2210 test_missingEnumConstantInSwitch() async { |
| 2182 Source source = addSource(r''' | 2211 Source source = addSource(r''' |
| 2183 enum E { ONE, TWO, THREE, FOUR } | 2212 enum E { ONE, TWO, THREE, FOUR } |
| 2184 bool odd(E e) { | 2213 bool odd(E e) { |
| 2185 switch (e) { | 2214 switch (e) { |
| 2186 case E.ONE: | 2215 case E.ONE: |
| 2187 case E.THREE: return true; | 2216 case E.THREE: return true; |
| 2188 } | 2217 } |
| 2189 return false; | 2218 return false; |
| 2190 }'''); | 2219 }'''); |
| 2191 assertErrors(source, [ | 2220 await assertErrors(source, [ |
| 2192 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH, | 2221 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH, |
| 2193 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH | 2222 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH |
| 2194 ]); | 2223 ]); |
| 2195 verify([source]); | 2224 verify([source]); |
| 2196 } | 2225 } |
| 2197 | 2226 |
| 2198 void test_mixedReturnTypes_localFunction() { | 2227 test_mixedReturnTypes_localFunction() async { |
| 2199 Source source = addSource(r''' | 2228 Source source = addSource(r''' |
| 2200 class C { | 2229 class C { |
| 2201 m(int x) { | 2230 m(int x) { |
| 2202 return (int y) { | 2231 return (int y) { |
| 2203 if (y < 0) { | 2232 if (y < 0) { |
| 2204 return; | 2233 return; |
| 2205 } | 2234 } |
| 2206 return 0; | 2235 return 0; |
| 2207 }; | 2236 }; |
| 2208 } | 2237 } |
| 2209 }'''); | 2238 }'''); |
| 2210 assertErrors(source, [ | 2239 await assertErrors(source, [ |
| 2211 StaticWarningCode.MIXED_RETURN_TYPES, | 2240 StaticWarningCode.MIXED_RETURN_TYPES, |
| 2212 StaticWarningCode.MIXED_RETURN_TYPES | 2241 StaticWarningCode.MIXED_RETURN_TYPES |
| 2213 ]); | 2242 ]); |
| 2214 verify([source]); | 2243 verify([source]); |
| 2215 } | 2244 } |
| 2216 | 2245 |
| 2217 void test_mixedReturnTypes_method() { | 2246 test_mixedReturnTypes_method() async { |
| 2218 Source source = addSource(r''' | 2247 Source source = addSource(r''' |
| 2219 class C { | 2248 class C { |
| 2220 m(int x) { | 2249 m(int x) { |
| 2221 if (x < 0) { | 2250 if (x < 0) { |
| 2222 return; | 2251 return; |
| 2223 } | 2252 } |
| 2224 return 0; | 2253 return 0; |
| 2225 } | 2254 } |
| 2226 }'''); | 2255 }'''); |
| 2227 assertErrors(source, [ | 2256 await assertErrors(source, [ |
| 2228 StaticWarningCode.MIXED_RETURN_TYPES, | 2257 StaticWarningCode.MIXED_RETURN_TYPES, |
| 2229 StaticWarningCode.MIXED_RETURN_TYPES | 2258 StaticWarningCode.MIXED_RETURN_TYPES |
| 2230 ]); | 2259 ]); |
| 2231 verify([source]); | 2260 verify([source]); |
| 2232 } | 2261 } |
| 2233 | 2262 |
| 2234 void test_mixedReturnTypes_topLevelFunction() { | 2263 test_mixedReturnTypes_topLevelFunction() async { |
| 2235 Source source = addSource(r''' | 2264 Source source = addSource(r''' |
| 2236 f(int x) { | 2265 f(int x) { |
| 2237 if (x < 0) { | 2266 if (x < 0) { |
| 2238 return; | 2267 return; |
| 2239 } | 2268 } |
| 2240 return 0; | 2269 return 0; |
| 2241 }'''); | 2270 }'''); |
| 2242 assertErrors(source, [ | 2271 await assertErrors(source, [ |
| 2243 StaticWarningCode.MIXED_RETURN_TYPES, | 2272 StaticWarningCode.MIXED_RETURN_TYPES, |
| 2244 StaticWarningCode.MIXED_RETURN_TYPES | 2273 StaticWarningCode.MIXED_RETURN_TYPES |
| 2245 ]); | 2274 ]); |
| 2246 verify([source]); | 2275 verify([source]); |
| 2247 } | 2276 } |
| 2248 | 2277 |
| 2249 void test_newWithAbstractClass() { | 2278 test_newWithAbstractClass() async { |
| 2250 Source source = addSource(r''' | 2279 Source source = addSource(r''' |
| 2251 abstract class A {} | 2280 abstract class A {} |
| 2252 void f() { | 2281 void f() { |
| 2253 A a = new A(); | 2282 A a = new A(); |
| 2254 }'''); | 2283 }'''); |
| 2255 assertErrors(source, [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]); | 2284 await assertErrors(source, [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]); |
| 2256 verify([source]); | 2285 verify([source]); |
| 2257 } | 2286 } |
| 2258 | 2287 |
| 2259 void test_newWithInvalidTypeParameters() { | 2288 test_newWithInvalidTypeParameters() async { |
| 2260 Source source = addSource(r''' | 2289 Source source = addSource(r''' |
| 2261 class A {} | 2290 class A {} |
| 2262 f() { return new A<A>(); }'''); | 2291 f() { return new A<A>(); }'''); |
| 2263 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); | 2292 await assertErrors( |
| 2293 source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); |
| 2264 verify([source]); | 2294 verify([source]); |
| 2265 } | 2295 } |
| 2266 | 2296 |
| 2267 void test_newWithInvalidTypeParameters_tooFew() { | 2297 test_newWithInvalidTypeParameters_tooFew() async { |
| 2268 Source source = addSource(r''' | 2298 Source source = addSource(r''' |
| 2269 class A {} | 2299 class A {} |
| 2270 class C<K, V> {} | 2300 class C<K, V> {} |
| 2271 f(p) { | 2301 f(p) { |
| 2272 return new C<A>(); | 2302 return new C<A>(); |
| 2273 }'''); | 2303 }'''); |
| 2274 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); | 2304 await assertErrors( |
| 2305 source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); |
| 2275 verify([source]); | 2306 verify([source]); |
| 2276 } | 2307 } |
| 2277 | 2308 |
| 2278 void test_newWithInvalidTypeParameters_tooMany() { | 2309 test_newWithInvalidTypeParameters_tooMany() async { |
| 2279 Source source = addSource(r''' | 2310 Source source = addSource(r''' |
| 2280 class A {} | 2311 class A {} |
| 2281 class C<E> {} | 2312 class C<E> {} |
| 2282 f(p) { | 2313 f(p) { |
| 2283 return new C<A, A>(); | 2314 return new C<A, A>(); |
| 2284 }'''); | 2315 }'''); |
| 2285 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); | 2316 await assertErrors( |
| 2317 source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); |
| 2286 verify([source]); | 2318 verify([source]); |
| 2287 } | 2319 } |
| 2288 | 2320 |
| 2289 void test_newWithNonType() { | 2321 test_newWithNonType() async { |
| 2290 Source source = addSource(r''' | 2322 Source source = addSource(r''' |
| 2291 var A = 0; | 2323 var A = 0; |
| 2292 void f() { | 2324 void f() { |
| 2293 var a = new A(); | 2325 var a = new A(); |
| 2294 }'''); | 2326 }'''); |
| 2295 assertErrors(source, [StaticWarningCode.NEW_WITH_NON_TYPE]); | 2327 await assertErrors(source, [StaticWarningCode.NEW_WITH_NON_TYPE]); |
| 2296 verify([source]); | 2328 verify([source]); |
| 2297 } | 2329 } |
| 2298 | 2330 |
| 2299 void test_newWithNonType_fromLibrary() { | 2331 test_newWithNonType_fromLibrary() async { |
| 2300 Source source1 = addNamedSource("/lib.dart", "class B {}"); | 2332 Source source1 = addNamedSource("/lib.dart", "class B {}"); |
| 2301 Source source2 = addNamedSource( | 2333 Source source2 = addNamedSource( |
| 2302 "/lib2.dart", | 2334 "/lib2.dart", |
| 2303 r''' | 2335 r''' |
| 2304 import 'lib.dart' as lib; | 2336 import 'lib.dart' as lib; |
| 2305 void f() { | 2337 void f() { |
| 2306 var a = new lib.A(); | 2338 var a = new lib.A(); |
| 2307 } | 2339 } |
| 2308 lib.B b;'''); | 2340 lib.B b;'''); |
| 2309 assertErrors(source2, [StaticWarningCode.NEW_WITH_NON_TYPE]); | 2341 await assertErrors(source2, [StaticWarningCode.NEW_WITH_NON_TYPE]); |
| 2310 verify([source1]); | 2342 verify([source1]); |
| 2311 } | 2343 } |
| 2312 | 2344 |
| 2313 void test_newWithUndefinedConstructor() { | 2345 test_newWithUndefinedConstructor() async { |
| 2314 Source source = addSource(r''' | 2346 Source source = addSource(r''' |
| 2315 class A { | 2347 class A { |
| 2316 A() {} | 2348 A() {} |
| 2317 } | 2349 } |
| 2318 f() { | 2350 f() { |
| 2319 new A.name(); | 2351 new A.name(); |
| 2320 }'''); | 2352 }'''); |
| 2321 assertErrors(source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]); | 2353 await assertErrors( |
| 2354 source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]); |
| 2322 // no verify(), 'name' is not resolved | 2355 // no verify(), 'name' is not resolved |
| 2323 } | 2356 } |
| 2324 | 2357 |
| 2325 void test_newWithUndefinedConstructorDefault() { | 2358 test_newWithUndefinedConstructorDefault() async { |
| 2326 Source source = addSource(r''' | 2359 Source source = addSource(r''' |
| 2327 class A { | 2360 class A { |
| 2328 A.name() {} | 2361 A.name() {} |
| 2329 } | 2362 } |
| 2330 f() { | 2363 f() { |
| 2331 new A(); | 2364 new A(); |
| 2332 }'''); | 2365 }'''); |
| 2333 assertErrors( | 2366 await assertErrors( |
| 2334 source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); | 2367 source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); |
| 2335 verify([source]); | 2368 verify([source]); |
| 2336 } | 2369 } |
| 2337 | 2370 |
| 2338 void test_nonAbstractClassInheritsAbstractMemberFivePlus() { | 2371 test_nonAbstractClassInheritsAbstractMemberFivePlus() async { |
| 2339 Source source = addSource(r''' | 2372 Source source = addSource(r''' |
| 2340 abstract class A { | 2373 abstract class A { |
| 2341 m(); | 2374 m(); |
| 2342 n(); | 2375 n(); |
| 2343 o(); | 2376 o(); |
| 2344 p(); | 2377 p(); |
| 2345 q(); | 2378 q(); |
| 2346 } | 2379 } |
| 2347 class C extends A { | 2380 class C extends A { |
| 2348 }'''); | 2381 }'''); |
| 2349 assertErrors(source, [ | 2382 await assertErrors(source, [ |
| 2350 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS | 2383 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS |
| 2351 ]); | 2384 ]); |
| 2352 verify([source]); | 2385 verify([source]); |
| 2353 } | 2386 } |
| 2354 | 2387 |
| 2355 void test_nonAbstractClassInheritsAbstractMemberFour() { | 2388 test_nonAbstractClassInheritsAbstractMemberFour() async { |
| 2356 Source source = addSource(r''' | 2389 Source source = addSource(r''' |
| 2357 abstract class A { | 2390 abstract class A { |
| 2358 m(); | 2391 m(); |
| 2359 n(); | 2392 n(); |
| 2360 o(); | 2393 o(); |
| 2361 p(); | 2394 p(); |
| 2362 } | 2395 } |
| 2363 class C extends A { | 2396 class C extends A { |
| 2364 }'''); | 2397 }'''); |
| 2365 assertErrors(source, | 2398 await assertErrors(source, |
| 2366 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR]); | 2399 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR]); |
| 2367 verify([source]); | 2400 verify([source]); |
| 2368 } | 2401 } |
| 2369 | 2402 |
| 2370 void | 2403 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface() asyn
c { |
| 2371 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface()
{ | |
| 2372 // 15979 | 2404 // 15979 |
| 2373 Source source = addSource(r''' | 2405 Source source = addSource(r''' |
| 2374 abstract class M {} | 2406 abstract class M {} |
| 2375 abstract class A {} | 2407 abstract class A {} |
| 2376 abstract class I { | 2408 abstract class I { |
| 2377 m(); | 2409 m(); |
| 2378 } | 2410 } |
| 2379 class B = A with M implements I;'''); | 2411 class B = A with M implements I;'''); |
| 2380 assertErrors(source, | 2412 await assertErrors(source, |
| 2381 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2413 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2382 verify([source]); | 2414 verify([source]); |
| 2383 } | 2415 } |
| 2384 | 2416 |
| 2385 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() { | 2417 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() async { |
| 2386 // 15979 | 2418 // 15979 |
| 2387 Source source = addSource(r''' | 2419 Source source = addSource(r''' |
| 2388 abstract class M { | 2420 abstract class M { |
| 2389 m(); | 2421 m(); |
| 2390 } | 2422 } |
| 2391 abstract class A {} | 2423 abstract class A {} |
| 2392 class B = A with M;'''); | 2424 class B = A with M;'''); |
| 2393 assertErrors(source, | 2425 await assertErrors(source, |
| 2394 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2426 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2395 verify([source]); | 2427 verify([source]); |
| 2396 } | 2428 } |
| 2397 | 2429 |
| 2398 void | 2430 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass() asy
nc { |
| 2399 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass()
{ | |
| 2400 // 15979 | 2431 // 15979 |
| 2401 Source source = addSource(r''' | 2432 Source source = addSource(r''' |
| 2402 class M {} | 2433 class M {} |
| 2403 abstract class A { | 2434 abstract class A { |
| 2404 m(); | 2435 m(); |
| 2405 } | 2436 } |
| 2406 class B = A with M;'''); | 2437 class B = A with M;'''); |
| 2407 assertErrors(source, | 2438 await assertErrors(source, |
| 2408 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2439 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2409 verify([source]); | 2440 verify([source]); |
| 2410 } | 2441 } |
| 2411 | 2442 |
| 2412 void | 2443 test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubtypeIsU
sedInImplementation() async { |
| 2413 test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubtyp
eIsUsedInImplementation() { | |
| 2414 // 15028 | 2444 // 15028 |
| 2415 Source source = addSource(r''' | 2445 Source source = addSource(r''' |
| 2416 class C { | 2446 class C { |
| 2417 foo(int x) => x; | 2447 foo(int x) => x; |
| 2418 } | 2448 } |
| 2419 abstract class D { | 2449 abstract class D { |
| 2420 foo(x, [y]); | 2450 foo(x, [y]); |
| 2421 } | 2451 } |
| 2422 class E extends C implements D {}'''); | 2452 class E extends C implements D {}'''); |
| 2423 assertErrors(source, | 2453 await assertErrors(source, |
| 2424 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2454 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2425 verify([source]); | 2455 verify([source]); |
| 2426 } | 2456 } |
| 2427 | 2457 |
| 2428 void test_nonAbstractClassInheritsAbstractMemberOne_getter_fromInterface() { | 2458 test_nonAbstractClassInheritsAbstractMemberOne_getter_fromInterface() async { |
| 2429 Source source = addSource(r''' | 2459 Source source = addSource(r''' |
| 2430 class I { | 2460 class I { |
| 2431 int get g {return 1;} | 2461 int get g {return 1;} |
| 2432 } | 2462 } |
| 2433 class C implements I { | 2463 class C implements I { |
| 2434 }'''); | 2464 }'''); |
| 2435 assertErrors(source, | 2465 await assertErrors(source, |
| 2436 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2466 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2437 verify([source]); | 2467 verify([source]); |
| 2438 } | 2468 } |
| 2439 | 2469 |
| 2440 void test_nonAbstractClassInheritsAbstractMemberOne_getter_fromSuperclass() { | 2470 test_nonAbstractClassInheritsAbstractMemberOne_getter_fromSuperclass() async { |
| 2441 Source source = addSource(r''' | 2471 Source source = addSource(r''' |
| 2442 abstract class A { | 2472 abstract class A { |
| 2443 int get g; | 2473 int get g; |
| 2444 } | 2474 } |
| 2445 class C extends A { | 2475 class C extends A { |
| 2446 }'''); | 2476 }'''); |
| 2447 assertErrors(source, | 2477 await assertErrors(source, |
| 2448 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2478 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2449 verify([source]); | 2479 verify([source]); |
| 2450 } | 2480 } |
| 2451 | 2481 |
| 2452 void test_nonAbstractClassInheritsAbstractMemberOne_method_fromInterface() { | 2482 test_nonAbstractClassInheritsAbstractMemberOne_method_fromInterface() async { |
| 2453 Source source = addSource(r''' | 2483 Source source = addSource(r''' |
| 2454 class I { | 2484 class I { |
| 2455 m(p) {} | 2485 m(p) {} |
| 2456 } | 2486 } |
| 2457 class C implements I { | 2487 class C implements I { |
| 2458 }'''); | 2488 }'''); |
| 2459 assertErrors(source, | 2489 await assertErrors(source, |
| 2460 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2490 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2461 verify([source]); | 2491 verify([source]); |
| 2462 } | 2492 } |
| 2463 | 2493 |
| 2464 void test_nonAbstractClassInheritsAbstractMemberOne_method_fromSuperclass() { | 2494 test_nonAbstractClassInheritsAbstractMemberOne_method_fromSuperclass() async { |
| 2465 Source source = addSource(r''' | 2495 Source source = addSource(r''' |
| 2466 abstract class A { | 2496 abstract class A { |
| 2467 m(p); | 2497 m(p); |
| 2468 } | 2498 } |
| 2469 class C extends A { | 2499 class C extends A { |
| 2470 }'''); | 2500 }'''); |
| 2471 assertErrors(source, | 2501 await assertErrors(source, |
| 2472 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2502 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2473 verify([source]); | 2503 verify([source]); |
| 2474 } | 2504 } |
| 2475 | 2505 |
| 2476 void | 2506 test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount() asy
nc { |
| 2477 test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount()
{ | |
| 2478 // 7640 | 2507 // 7640 |
| 2479 Source source = addSource(r''' | 2508 Source source = addSource(r''' |
| 2480 abstract class A { | 2509 abstract class A { |
| 2481 int x(int a); | 2510 int x(int a); |
| 2482 } | 2511 } |
| 2483 abstract class B { | 2512 abstract class B { |
| 2484 int x(int a, [int b]); | 2513 int x(int a, [int b]); |
| 2485 } | 2514 } |
| 2486 class C implements A, B { | 2515 class C implements A, B { |
| 2487 }'''); | 2516 }'''); |
| 2488 assertErrors(source, | 2517 await assertErrors(source, |
| 2489 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2518 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2490 verify([source]); | 2519 verify([source]); |
| 2491 } | 2520 } |
| 2492 | 2521 |
| 2493 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_getter() { | 2522 test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_getter() async { |
| 2494 // 15001 | 2523 // 15001 |
| 2495 Source source = addSource(r''' | 2524 Source source = addSource(r''' |
| 2496 abstract class A { get g1; get g2; } | 2525 abstract class A { get g1; get g2; } |
| 2497 abstract class B implements A { get g1 => 1; } | 2526 abstract class B implements A { get g1 => 1; } |
| 2498 class C extends Object with B {}'''); | 2527 class C extends Object with B {}'''); |
| 2499 assertErrors(source, | 2528 await assertErrors(source, |
| 2500 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2529 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2501 } | 2530 } |
| 2502 | 2531 |
| 2503 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_method() { | 2532 test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_method() async { |
| 2504 // 15001 | 2533 // 15001 |
| 2505 Source source = addSource(r''' | 2534 Source source = addSource(r''' |
| 2506 abstract class A { m1(); m2(); } | 2535 abstract class A { m1(); m2(); } |
| 2507 abstract class B implements A { m1() => 1; } | 2536 abstract class B implements A { m1() => 1; } |
| 2508 class C extends Object with B {}'''); | 2537 class C extends Object with B {}'''); |
| 2509 assertErrors(source, | 2538 await assertErrors(source, |
| 2510 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2539 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2511 } | 2540 } |
| 2512 | 2541 |
| 2513 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_setter() { | 2542 test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_setter() async { |
| 2514 // 15001 | 2543 // 15001 |
| 2515 Source source = addSource(r''' | 2544 Source source = addSource(r''' |
| 2516 abstract class A { set s1(v); set s2(v); } | 2545 abstract class A { set s1(v); set s2(v); } |
| 2517 abstract class B implements A { set s1(v) {} } | 2546 abstract class B implements A { set s1(v) {} } |
| 2518 class C extends Object with B {}'''); | 2547 class C extends Object with B {}'''); |
| 2519 assertErrors(source, | 2548 await assertErrors(source, |
| 2520 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2549 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2521 } | 2550 } |
| 2522 | 2551 |
| 2523 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_interface() { | 2552 test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_interface() async
{ |
| 2524 // 15979 | 2553 // 15979 |
| 2525 Source source = addSource(r''' | 2554 Source source = addSource(r''' |
| 2526 class I { | 2555 class I { |
| 2527 noSuchMethod(v) => ''; | 2556 noSuchMethod(v) => ''; |
| 2528 } | 2557 } |
| 2529 abstract class A { | 2558 abstract class A { |
| 2530 m(); | 2559 m(); |
| 2531 } | 2560 } |
| 2532 class B extends A implements I { | 2561 class B extends A implements I { |
| 2533 }'''); | 2562 }'''); |
| 2534 assertErrors(source, | 2563 await assertErrors(source, |
| 2535 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2564 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2536 verify([source]); | 2565 verify([source]); |
| 2537 } | 2566 } |
| 2538 | 2567 |
| 2539 void | 2568 test_nonAbstractClassInheritsAbstractMemberOne_setter_and_implicitSetter() asy
nc { |
| 2540 test_nonAbstractClassInheritsAbstractMemberOne_setter_and_implicitSetter()
{ | |
| 2541 // test from language/override_inheritance_abstract_test_14.dart | 2569 // test from language/override_inheritance_abstract_test_14.dart |
| 2542 Source source = addSource(r''' | 2570 Source source = addSource(r''' |
| 2543 abstract class A { | 2571 abstract class A { |
| 2544 set field(_); | 2572 set field(_); |
| 2545 } | 2573 } |
| 2546 abstract class I { | 2574 abstract class I { |
| 2547 var field; | 2575 var field; |
| 2548 } | 2576 } |
| 2549 class B extends A implements I { | 2577 class B extends A implements I { |
| 2550 get field => 0; | 2578 get field => 0; |
| 2551 }'''); | 2579 }'''); |
| 2552 assertErrors(source, | 2580 await assertErrors(source, |
| 2553 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2581 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2554 verify([source]); | 2582 verify([source]); |
| 2555 } | 2583 } |
| 2556 | 2584 |
| 2557 void test_nonAbstractClassInheritsAbstractMemberOne_setter_fromInterface() { | 2585 test_nonAbstractClassInheritsAbstractMemberOne_setter_fromInterface() async { |
| 2558 Source source = addSource(r''' | 2586 Source source = addSource(r''' |
| 2559 class I { | 2587 class I { |
| 2560 set s(int i) {} | 2588 set s(int i) {} |
| 2561 } | 2589 } |
| 2562 class C implements I { | 2590 class C implements I { |
| 2563 }'''); | 2591 }'''); |
| 2564 assertErrors(source, | 2592 await assertErrors(source, |
| 2565 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2593 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2566 verify([source]); | 2594 verify([source]); |
| 2567 } | 2595 } |
| 2568 | 2596 |
| 2569 void test_nonAbstractClassInheritsAbstractMemberOne_setter_fromSuperclass() { | 2597 test_nonAbstractClassInheritsAbstractMemberOne_setter_fromSuperclass() async { |
| 2570 Source source = addSource(r''' | 2598 Source source = addSource(r''' |
| 2571 abstract class A { | 2599 abstract class A { |
| 2572 set s(int i); | 2600 set s(int i); |
| 2573 } | 2601 } |
| 2574 class C extends A { | 2602 class C extends A { |
| 2575 }'''); | 2603 }'''); |
| 2576 assertErrors(source, | 2604 await assertErrors(source, |
| 2577 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2605 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2578 verify([source]); | 2606 verify([source]); |
| 2579 } | 2607 } |
| 2580 | 2608 |
| 2581 void test_nonAbstractClassInheritsAbstractMemberOne_superclasses_interface() { | 2609 test_nonAbstractClassInheritsAbstractMemberOne_superclasses_interface() async
{ |
| 2582 // bug 11154 | 2610 // bug 11154 |
| 2583 Source source = addSource(r''' | 2611 Source source = addSource(r''' |
| 2584 class A { | 2612 class A { |
| 2585 get a => 'a'; | 2613 get a => 'a'; |
| 2586 } | 2614 } |
| 2587 abstract class B implements A { | 2615 abstract class B implements A { |
| 2588 get b => 'b'; | 2616 get b => 'b'; |
| 2589 } | 2617 } |
| 2590 class C extends B { | 2618 class C extends B { |
| 2591 }'''); | 2619 }'''); |
| 2592 assertErrors(source, | 2620 await assertErrors(source, |
| 2593 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2621 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2594 verify([source]); | 2622 verify([source]); |
| 2595 } | 2623 } |
| 2596 | 2624 |
| 2597 void | 2625 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_missingG
etter() async { |
| 2598 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss
ingGetter() { | |
| 2599 // 16133 | 2626 // 16133 |
| 2600 Source source = addSource(r''' | 2627 Source source = addSource(r''' |
| 2601 class I { | 2628 class I { |
| 2602 var v; | 2629 var v; |
| 2603 } | 2630 } |
| 2604 class C implements I { | 2631 class C implements I { |
| 2605 set v(_) {} | 2632 set v(_) {} |
| 2606 }'''); | 2633 }'''); |
| 2607 assertErrors(source, | 2634 await assertErrors(source, |
| 2608 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2635 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2609 verify([source]); | 2636 verify([source]); |
| 2610 } | 2637 } |
| 2611 | 2638 |
| 2612 void | 2639 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_missingS
etter() async { |
| 2613 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss
ingSetter() { | |
| 2614 // 16133 | 2640 // 16133 |
| 2615 Source source = addSource(r''' | 2641 Source source = addSource(r''' |
| 2616 class I { | 2642 class I { |
| 2617 var v; | 2643 var v; |
| 2618 } | 2644 } |
| 2619 class C implements I { | 2645 class C implements I { |
| 2620 get v => 1; | 2646 get v => 1; |
| 2621 }'''); | 2647 }'''); |
| 2622 assertErrors(source, | 2648 await assertErrors(source, |
| 2623 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2649 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2624 verify([source]); | 2650 verify([source]); |
| 2625 } | 2651 } |
| 2626 | 2652 |
| 2627 void test_nonAbstractClassInheritsAbstractMemberThree() { | 2653 test_nonAbstractClassInheritsAbstractMemberThree() async { |
| 2628 Source source = addSource(r''' | 2654 Source source = addSource(r''' |
| 2629 abstract class A { | 2655 abstract class A { |
| 2630 m(); | 2656 m(); |
| 2631 n(); | 2657 n(); |
| 2632 o(); | 2658 o(); |
| 2633 } | 2659 } |
| 2634 class C extends A { | 2660 class C extends A { |
| 2635 }'''); | 2661 }'''); |
| 2636 assertErrors(source, | 2662 await assertErrors(source, |
| 2637 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE]); | 2663 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE]); |
| 2638 verify([source]); | 2664 verify([source]); |
| 2639 } | 2665 } |
| 2640 | 2666 |
| 2641 void test_nonAbstractClassInheritsAbstractMemberTwo() { | 2667 test_nonAbstractClassInheritsAbstractMemberTwo() async { |
| 2642 Source source = addSource(r''' | 2668 Source source = addSource(r''' |
| 2643 abstract class A { | 2669 abstract class A { |
| 2644 m(); | 2670 m(); |
| 2645 n(); | 2671 n(); |
| 2646 } | 2672 } |
| 2647 class C extends A { | 2673 class C extends A { |
| 2648 }'''); | 2674 }'''); |
| 2649 assertErrors(source, | 2675 await assertErrors(source, |
| 2650 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); | 2676 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); |
| 2651 verify([source]); | 2677 verify([source]); |
| 2652 } | 2678 } |
| 2653 | 2679 |
| 2654 void | 2680 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromInterface_missingB
oth() async { |
| 2655 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromInterface_miss
ingBoth() { | |
| 2656 // 16133 | 2681 // 16133 |
| 2657 Source source = addSource(r''' | 2682 Source source = addSource(r''' |
| 2658 class I { | 2683 class I { |
| 2659 var v; | 2684 var v; |
| 2660 } | 2685 } |
| 2661 class C implements I { | 2686 class C implements I { |
| 2662 }'''); | 2687 }'''); |
| 2663 assertErrors(source, | 2688 await assertErrors(source, |
| 2664 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); | 2689 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); |
| 2665 verify([source]); | 2690 verify([source]); |
| 2666 } | 2691 } |
| 2667 | 2692 |
| 2668 void | 2693 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromMixin_missingBoth(
) async { |
| 2669 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromMixin_missingB
oth() { | |
| 2670 // 26411 | 2694 // 26411 |
| 2671 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); | 2695 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); |
| 2672 Source source = addSource(r''' | 2696 Source source = addSource(r''' |
| 2673 class A { | 2697 class A { |
| 2674 int f; | 2698 int f; |
| 2675 } | 2699 } |
| 2676 class B extends A {} | 2700 class B extends A {} |
| 2677 class C extends Object with B {} | 2701 class C extends Object with B {} |
| 2678 '''); | 2702 '''); |
| 2679 assertErrors(source, | 2703 await assertErrors(source, |
| 2680 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); | 2704 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); |
| 2681 verify([source]); | 2705 verify([source]); |
| 2682 } | 2706 } |
| 2683 | 2707 |
| 2684 void test_nonTypeInCatchClause_noElement() { | 2708 test_nonTypeInCatchClause_noElement() async { |
| 2685 Source source = addSource(r''' | 2709 Source source = addSource(r''' |
| 2686 f() { | 2710 f() { |
| 2687 try { | 2711 try { |
| 2688 } on T catch (e) { | 2712 } on T catch (e) { |
| 2689 } | 2713 } |
| 2690 }'''); | 2714 }'''); |
| 2691 assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]); | 2715 await assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]); |
| 2692 verify([source]); | 2716 verify([source]); |
| 2693 } | 2717 } |
| 2694 | 2718 |
| 2695 void test_nonTypeInCatchClause_notType() { | 2719 test_nonTypeInCatchClause_notType() async { |
| 2696 Source source = addSource(r''' | 2720 Source source = addSource(r''' |
| 2697 var T = 0; | 2721 var T = 0; |
| 2698 f() { | 2722 f() { |
| 2699 try { | 2723 try { |
| 2700 } on T catch (e) { | 2724 } on T catch (e) { |
| 2701 } | 2725 } |
| 2702 }'''); | 2726 }'''); |
| 2703 assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]); | 2727 await assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]); |
| 2704 verify([source]); | 2728 verify([source]); |
| 2705 } | 2729 } |
| 2706 | 2730 |
| 2707 void test_nonVoidReturnForOperator() { | 2731 test_nonVoidReturnForOperator() async { |
| 2708 Source source = addSource(r''' | 2732 Source source = addSource(r''' |
| 2709 class A { | 2733 class A { |
| 2710 int operator []=(a, b) { return a; } | 2734 int operator []=(a, b) { return a; } |
| 2711 }'''); | 2735 }'''); |
| 2712 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]); | 2736 await assertErrors( |
| 2737 source, [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]); |
| 2713 verify([source]); | 2738 verify([source]); |
| 2714 } | 2739 } |
| 2715 | 2740 |
| 2716 void test_nonVoidReturnForSetter_function() { | 2741 test_nonVoidReturnForSetter_function() async { |
| 2717 Source source = addSource(r''' | 2742 Source source = addSource(r''' |
| 2718 int set x(int v) { | 2743 int set x(int v) { |
| 2719 return 42; | 2744 return 42; |
| 2720 }'''); | 2745 }'''); |
| 2721 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]); | 2746 await assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]); |
| 2722 verify([source]); | 2747 verify([source]); |
| 2723 } | 2748 } |
| 2724 | 2749 |
| 2725 void test_nonVoidReturnForSetter_method() { | 2750 test_nonVoidReturnForSetter_method() async { |
| 2726 Source source = addSource(r''' | 2751 Source source = addSource(r''' |
| 2727 class A { | 2752 class A { |
| 2728 int set x(int v) { | 2753 int set x(int v) { |
| 2729 return 42; | 2754 return 42; |
| 2730 } | 2755 } |
| 2731 }'''); | 2756 }'''); |
| 2732 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]); | 2757 await assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]); |
| 2733 verify([source]); | 2758 verify([source]); |
| 2734 } | 2759 } |
| 2735 | 2760 |
| 2736 void test_notAType() { | 2761 test_notAType() async { |
| 2737 Source source = addSource(r''' | 2762 Source source = addSource(r''' |
| 2738 f() {} | 2763 f() {} |
| 2739 main() { | 2764 main() { |
| 2740 f v = null; | 2765 f v = null; |
| 2741 }'''); | 2766 }'''); |
| 2742 assertErrors(source, [StaticWarningCode.NOT_A_TYPE]); | 2767 await assertErrors(source, [StaticWarningCode.NOT_A_TYPE]); |
| 2743 verify([source]); | 2768 verify([source]); |
| 2744 } | 2769 } |
| 2745 | 2770 |
| 2746 void test_notEnoughRequiredArguments() { | 2771 test_notEnoughRequiredArguments() async { |
| 2747 Source source = addSource(r''' | 2772 Source source = addSource(r''' |
| 2748 f(int a, String b) {} | 2773 f(int a, String b) {} |
| 2749 main() { | 2774 main() { |
| 2750 f(); | 2775 f(); |
| 2751 }'''); | 2776 }'''); |
| 2752 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); | 2777 await assertErrors( |
| 2778 source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
| 2753 verify([source]); | 2779 verify([source]); |
| 2754 } | 2780 } |
| 2755 | 2781 |
| 2756 void test_notEnoughRequiredArguments_functionExpression() { | 2782 test_notEnoughRequiredArguments_functionExpression() async { |
| 2757 Source source = addSource(r''' | 2783 Source source = addSource(r''' |
| 2758 main() { | 2784 main() { |
| 2759 (int x) {} (); | 2785 (int x) {} (); |
| 2760 }'''); | 2786 }'''); |
| 2761 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); | 2787 await assertErrors( |
| 2788 source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
| 2762 verify([source]); | 2789 verify([source]); |
| 2763 } | 2790 } |
| 2764 | 2791 |
| 2765 void test_notEnoughRequiredArguments_getterReturningFunction() { | 2792 test_notEnoughRequiredArguments_getterReturningFunction() async { |
| 2766 Source source = addSource(r''' | 2793 Source source = addSource(r''' |
| 2767 typedef Getter(self); | 2794 typedef Getter(self); |
| 2768 Getter getter = (x) => x; | 2795 Getter getter = (x) => x; |
| 2769 main() { | 2796 main() { |
| 2770 getter(); | 2797 getter(); |
| 2771 }'''); | 2798 }'''); |
| 2772 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); | 2799 await assertErrors( |
| 2800 source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
| 2773 verify([source]); | 2801 verify([source]); |
| 2774 } | 2802 } |
| 2775 | 2803 |
| 2776 void test_partOfDifferentLibrary() { | 2804 test_partOfDifferentLibrary() async { |
| 2777 Source source = addSource(r''' | 2805 Source source = addSource(r''' |
| 2778 library lib; | 2806 library lib; |
| 2779 part 'part.dart';'''); | 2807 part 'part.dart';'''); |
| 2780 addNamedSource("/part.dart", "part of lub;"); | 2808 addNamedSource("/part.dart", "part of lub;"); |
| 2781 assertErrors(source, [StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]); | 2809 await assertErrors(source, [StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]); |
| 2782 verify([source]); | 2810 verify([source]); |
| 2783 } | 2811 } |
| 2784 | 2812 |
| 2785 void test_redirectToInvalidFunctionType() { | 2813 test_redirectToInvalidFunctionType() async { |
| 2786 Source source = addSource(r''' | 2814 Source source = addSource(r''' |
| 2787 class A implements B { | 2815 class A implements B { |
| 2788 A(int p) {} | 2816 A(int p) {} |
| 2789 } | 2817 } |
| 2790 class B { | 2818 class B { |
| 2791 factory B() = A; | 2819 factory B() = A; |
| 2792 }'''); | 2820 }'''); |
| 2793 assertErrors(source, [StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE]); | 2821 await assertErrors( |
| 2822 source, [StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE]); |
| 2794 verify([source]); | 2823 verify([source]); |
| 2795 } | 2824 } |
| 2796 | 2825 |
| 2797 void test_redirectToInvalidReturnType() { | 2826 test_redirectToInvalidReturnType() async { |
| 2798 Source source = addSource(r''' | 2827 Source source = addSource(r''' |
| 2799 class A { | 2828 class A { |
| 2800 A() {} | 2829 A() {} |
| 2801 } | 2830 } |
| 2802 class B { | 2831 class B { |
| 2803 factory B() = A; | 2832 factory B() = A; |
| 2804 }'''); | 2833 }'''); |
| 2805 assertErrors(source, [StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE]); | 2834 await assertErrors( |
| 2835 source, [StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE]); |
| 2806 verify([source]); | 2836 verify([source]); |
| 2807 } | 2837 } |
| 2808 | 2838 |
| 2809 void test_redirectToMissingConstructor_named() { | 2839 test_redirectToMissingConstructor_named() async { |
| 2810 Source source = addSource(r''' | 2840 Source source = addSource(r''' |
| 2811 class A implements B{ | 2841 class A implements B{ |
| 2812 A() {} | 2842 A() {} |
| 2813 } | 2843 } |
| 2814 class B { | 2844 class B { |
| 2815 factory B() = A.name; | 2845 factory B() = A.name; |
| 2816 }'''); | 2846 }'''); |
| 2817 assertErrors(source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); | 2847 await assertErrors( |
| 2848 source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); |
| 2818 } | 2849 } |
| 2819 | 2850 |
| 2820 void test_redirectToMissingConstructor_unnamed() { | 2851 test_redirectToMissingConstructor_unnamed() async { |
| 2821 Source source = addSource(r''' | 2852 Source source = addSource(r''' |
| 2822 class A implements B{ | 2853 class A implements B{ |
| 2823 A.name() {} | 2854 A.name() {} |
| 2824 } | 2855 } |
| 2825 class B { | 2856 class B { |
| 2826 factory B() = A; | 2857 factory B() = A; |
| 2827 }'''); | 2858 }'''); |
| 2828 assertErrors(source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); | 2859 await assertErrors( |
| 2860 source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); |
| 2829 } | 2861 } |
| 2830 | 2862 |
| 2831 void test_redirectToNonClass_notAType() { | 2863 test_redirectToNonClass_notAType() async { |
| 2832 Source source = addSource(r''' | 2864 Source source = addSource(r''' |
| 2833 class B { | 2865 class B { |
| 2834 int A; | 2866 int A; |
| 2835 factory B() = A; | 2867 factory B() = A; |
| 2836 }'''); | 2868 }'''); |
| 2837 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); | 2869 await assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); |
| 2838 verify([source]); | 2870 verify([source]); |
| 2839 } | 2871 } |
| 2840 | 2872 |
| 2841 void test_redirectToNonClass_undefinedIdentifier() { | 2873 test_redirectToNonClass_undefinedIdentifier() async { |
| 2842 Source source = addSource(r''' | 2874 Source source = addSource(r''' |
| 2843 class B { | 2875 class B { |
| 2844 factory B() = A; | 2876 factory B() = A; |
| 2845 }'''); | 2877 }'''); |
| 2846 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); | 2878 await assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); |
| 2847 verify([source]); | 2879 verify([source]); |
| 2848 } | 2880 } |
| 2849 | 2881 |
| 2850 void test_returnWithoutValue_async() { | 2882 test_returnWithoutValue_async() async { |
| 2851 Source source = addSource(''' | 2883 Source source = addSource(''' |
| 2852 import 'dart:async'; | 2884 import 'dart:async'; |
| 2853 Future<int> f() async { | 2885 Future<int> f() async { |
| 2854 return; | 2886 return; |
| 2855 } | 2887 } |
| 2856 '''); | 2888 '''); |
| 2857 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); | 2889 await assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2858 verify([source]); | 2890 verify([source]); |
| 2859 } | 2891 } |
| 2860 | 2892 |
| 2861 void test_returnWithoutValue_factoryConstructor() { | 2893 test_returnWithoutValue_factoryConstructor() async { |
| 2862 Source source = addSource("class A { factory A() { return; } }"); | 2894 Source source = addSource("class A { factory A() { return; } }"); |
| 2863 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); | 2895 await assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2864 verify([source]); | 2896 verify([source]); |
| 2865 } | 2897 } |
| 2866 | 2898 |
| 2867 void test_returnWithoutValue_function() { | 2899 test_returnWithoutValue_function() async { |
| 2868 Source source = addSource("int f() { return; }"); | 2900 Source source = addSource("int f() { return; }"); |
| 2869 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); | 2901 await assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2870 verify([source]); | 2902 verify([source]); |
| 2871 } | 2903 } |
| 2872 | 2904 |
| 2873 void test_returnWithoutValue_method() { | 2905 test_returnWithoutValue_method() async { |
| 2874 Source source = addSource("class A { int m() { return; } }"); | 2906 Source source = addSource("class A { int m() { return; } }"); |
| 2875 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); | 2907 await assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2876 verify([source]); | 2908 verify([source]); |
| 2877 } | 2909 } |
| 2878 | 2910 |
| 2879 void test_returnWithoutValue_mixedReturnTypes_function() { | 2911 test_returnWithoutValue_mixedReturnTypes_function() async { |
| 2880 // Tests that only the RETURN_WITHOUT_VALUE warning is created, and no | 2912 // Tests that only the RETURN_WITHOUT_VALUE warning is created, and no |
| 2881 // MIXED_RETURN_TYPES are created. | 2913 // MIXED_RETURN_TYPES are created. |
| 2882 Source source = addSource(r''' | 2914 Source source = addSource(r''' |
| 2883 int f(int x) { | 2915 int f(int x) { |
| 2884 if (x < 0) { | 2916 if (x < 0) { |
| 2885 return 1; | 2917 return 1; |
| 2886 } | 2918 } |
| 2887 return; | 2919 return; |
| 2888 }'''); | 2920 }'''); |
| 2889 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); | 2921 await assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); |
| 2890 verify([source]); | 2922 verify([source]); |
| 2891 } | 2923 } |
| 2892 | 2924 |
| 2893 void test_staticAccessToInstanceMember_method_invocation() { | 2925 test_staticAccessToInstanceMember_method_invocation() async { |
| 2894 Source source = addSource(r''' | 2926 Source source = addSource(r''' |
| 2895 class A { | 2927 class A { |
| 2896 m() {} | 2928 m() {} |
| 2897 } | 2929 } |
| 2898 main() { | 2930 main() { |
| 2899 A.m(); | 2931 A.m(); |
| 2900 }'''); | 2932 }'''); |
| 2901 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); | 2933 await assertErrors( |
| 2934 source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); |
| 2902 verify([source]); | 2935 verify([source]); |
| 2903 } | 2936 } |
| 2904 | 2937 |
| 2905 void test_staticAccessToInstanceMember_method_reference() { | 2938 test_staticAccessToInstanceMember_method_reference() async { |
| 2906 Source source = addSource(r''' | 2939 Source source = addSource(r''' |
| 2907 class A { | 2940 class A { |
| 2908 m() {} | 2941 m() {} |
| 2909 } | 2942 } |
| 2910 main() { | 2943 main() { |
| 2911 A.m; | 2944 A.m; |
| 2912 }'''); | 2945 }'''); |
| 2913 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); | 2946 await assertErrors( |
| 2947 source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); |
| 2914 verify([source]); | 2948 verify([source]); |
| 2915 } | 2949 } |
| 2916 | 2950 |
| 2917 void test_staticAccessToInstanceMember_propertyAccess_field() { | 2951 test_staticAccessToInstanceMember_propertyAccess_field() async { |
| 2918 Source source = addSource(r''' | 2952 Source source = addSource(r''' |
| 2919 class A { | 2953 class A { |
| 2920 var f; | 2954 var f; |
| 2921 } | 2955 } |
| 2922 main() { | 2956 main() { |
| 2923 A.f; | 2957 A.f; |
| 2924 }'''); | 2958 }'''); |
| 2925 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); | 2959 await assertErrors( |
| 2960 source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); |
| 2926 verify([source]); | 2961 verify([source]); |
| 2927 } | 2962 } |
| 2928 | 2963 |
| 2929 void test_staticAccessToInstanceMember_propertyAccess_getter() { | 2964 test_staticAccessToInstanceMember_propertyAccess_getter() async { |
| 2930 Source source = addSource(r''' | 2965 Source source = addSource(r''' |
| 2931 class A { | 2966 class A { |
| 2932 get f => 42; | 2967 get f => 42; |
| 2933 } | 2968 } |
| 2934 main() { | 2969 main() { |
| 2935 A.f; | 2970 A.f; |
| 2936 }'''); | 2971 }'''); |
| 2937 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); | 2972 await assertErrors( |
| 2973 source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); |
| 2938 verify([source]); | 2974 verify([source]); |
| 2939 } | 2975 } |
| 2940 | 2976 |
| 2941 void test_staticAccessToInstanceMember_propertyAccess_setter() { | 2977 test_staticAccessToInstanceMember_propertyAccess_setter() async { |
| 2942 Source source = addSource(r''' | 2978 Source source = addSource(r''' |
| 2943 class A { | 2979 class A { |
| 2944 set f(x) {} | 2980 set f(x) {} |
| 2945 } | 2981 } |
| 2946 main() { | 2982 main() { |
| 2947 A.f = 42; | 2983 A.f = 42; |
| 2948 }'''); | 2984 }'''); |
| 2949 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); | 2985 await assertErrors( |
| 2986 source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); |
| 2950 verify([source]); | 2987 verify([source]); |
| 2951 } | 2988 } |
| 2952 | 2989 |
| 2953 void test_switchExpressionNotAssignable() { | 2990 test_switchExpressionNotAssignable() async { |
| 2954 Source source = addSource(r''' | 2991 Source source = addSource(r''' |
| 2955 f(int p) { | 2992 f(int p) { |
| 2956 switch (p) { | 2993 switch (p) { |
| 2957 case 'a': break; | 2994 case 'a': break; |
| 2958 } | 2995 } |
| 2959 }'''); | 2996 }'''); |
| 2960 assertErrors(source, [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]); | 2997 await assertErrors( |
| 2998 source, [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]); |
| 2961 verify([source]); | 2999 verify([source]); |
| 2962 } | 3000 } |
| 2963 | 3001 |
| 2964 void test_typeAnnotationDeferredClass_asExpression() { | 3002 test_typeAnnotationDeferredClass_asExpression() async { |
| 2965 resolveWithErrors(<String>[ | 3003 await resolveWithErrors(<String>[ |
| 2966 r''' | 3004 r''' |
| 2967 library lib1; | 3005 library lib1; |
| 2968 class A {}''', | 3006 class A {}''', |
| 2969 r''' | 3007 r''' |
| 2970 library root; | 3008 library root; |
| 2971 import 'lib1.dart' deferred as a; | 3009 import 'lib1.dart' deferred as a; |
| 2972 f(var v) { | 3010 f(var v) { |
| 2973 v as a.A; | 3011 v as a.A; |
| 2974 }''' | 3012 }''' |
| 2975 ], <ErrorCode>[ | 3013 ], <ErrorCode>[ |
| 2976 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3014 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 2977 ]); | 3015 ]); |
| 2978 } | 3016 } |
| 2979 | 3017 |
| 2980 void test_typeAnnotationDeferredClass_catchClause() { | 3018 test_typeAnnotationDeferredClass_catchClause() async { |
| 2981 resolveWithErrors(<String>[ | 3019 await resolveWithErrors(<String>[ |
| 2982 r''' | 3020 r''' |
| 2983 library lib1; | 3021 library lib1; |
| 2984 class A {}''', | 3022 class A {}''', |
| 2985 r''' | 3023 r''' |
| 2986 library root; | 3024 library root; |
| 2987 import 'lib1.dart' deferred as a; | 3025 import 'lib1.dart' deferred as a; |
| 2988 f(var v) { | 3026 f(var v) { |
| 2989 try { | 3027 try { |
| 2990 } on a.A { | 3028 } on a.A { |
| 2991 } | 3029 } |
| 2992 }''' | 3030 }''' |
| 2993 ], <ErrorCode>[ | 3031 ], <ErrorCode>[ |
| 2994 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3032 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 2995 ]); | 3033 ]); |
| 2996 } | 3034 } |
| 2997 | 3035 |
| 2998 void test_typeAnnotationDeferredClass_fieldFormalParameter() { | 3036 test_typeAnnotationDeferredClass_fieldFormalParameter() async { |
| 2999 resolveWithErrors(<String>[ | 3037 await resolveWithErrors(<String>[ |
| 3000 r''' | 3038 r''' |
| 3001 library lib1; | 3039 library lib1; |
| 3002 class A {}''', | 3040 class A {}''', |
| 3003 r''' | 3041 r''' |
| 3004 library root; | 3042 library root; |
| 3005 import 'lib1.dart' deferred as a; | 3043 import 'lib1.dart' deferred as a; |
| 3006 class C { | 3044 class C { |
| 3007 var v; | 3045 var v; |
| 3008 C(a.A this.v); | 3046 C(a.A this.v); |
| 3009 }''' | 3047 }''' |
| 3010 ], <ErrorCode>[ | 3048 ], <ErrorCode>[ |
| 3011 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3049 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3012 ]); | 3050 ]); |
| 3013 } | 3051 } |
| 3014 | 3052 |
| 3015 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() { | 3053 test_typeAnnotationDeferredClass_functionDeclaration_returnType() async { |
| 3016 resolveWithErrors(<String>[ | 3054 await resolveWithErrors(<String>[ |
| 3017 r''' | 3055 r''' |
| 3018 library lib1; | 3056 library lib1; |
| 3019 class A {}''', | 3057 class A {}''', |
| 3020 r''' | 3058 r''' |
| 3021 library root; | 3059 library root; |
| 3022 import 'lib1.dart' deferred as a; | 3060 import 'lib1.dart' deferred as a; |
| 3023 a.A f() { return null; }''' | 3061 a.A f() { return null; }''' |
| 3024 ], <ErrorCode>[ | 3062 ], <ErrorCode>[ |
| 3025 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3063 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3026 ]); | 3064 ]); |
| 3027 } | 3065 } |
| 3028 | 3066 |
| 3029 void | 3067 test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType() asy
nc { |
| 3030 test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType()
{ | 3068 await resolveWithErrors(<String>[ |
| 3031 resolveWithErrors(<String>[ | |
| 3032 r''' | 3069 r''' |
| 3033 library lib1; | 3070 library lib1; |
| 3034 class A {}''', | 3071 class A {}''', |
| 3035 r''' | 3072 r''' |
| 3036 library root; | 3073 library root; |
| 3037 import 'lib1.dart' deferred as a; | 3074 import 'lib1.dart' deferred as a; |
| 3038 f(a.A g()) {}''' | 3075 f(a.A g()) {}''' |
| 3039 ], <ErrorCode>[ | 3076 ], <ErrorCode>[ |
| 3040 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3077 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3041 ]); | 3078 ]); |
| 3042 } | 3079 } |
| 3043 | 3080 |
| 3044 void test_typeAnnotationDeferredClass_isExpression() { | 3081 test_typeAnnotationDeferredClass_isExpression() async { |
| 3045 resolveWithErrors(<String>[ | 3082 await resolveWithErrors(<String>[ |
| 3046 r''' | 3083 r''' |
| 3047 library lib1; | 3084 library lib1; |
| 3048 class A {}''', | 3085 class A {}''', |
| 3049 r''' | 3086 r''' |
| 3050 library root; | 3087 library root; |
| 3051 import 'lib1.dart' deferred as a; | 3088 import 'lib1.dart' deferred as a; |
| 3052 f(var v) { | 3089 f(var v) { |
| 3053 bool b = v is a.A; | 3090 bool b = v is a.A; |
| 3054 }''' | 3091 }''' |
| 3055 ], <ErrorCode>[ | 3092 ], <ErrorCode>[ |
| 3056 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3093 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3057 ]); | 3094 ]); |
| 3058 } | 3095 } |
| 3059 | 3096 |
| 3060 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() { | 3097 test_typeAnnotationDeferredClass_methodDeclaration_returnType() async { |
| 3061 resolveWithErrors(<String>[ | 3098 await resolveWithErrors(<String>[ |
| 3062 r''' | 3099 r''' |
| 3063 library lib1; | 3100 library lib1; |
| 3064 class A {}''', | 3101 class A {}''', |
| 3065 r''' | 3102 r''' |
| 3066 library root; | 3103 library root; |
| 3067 import 'lib1.dart' deferred as a; | 3104 import 'lib1.dart' deferred as a; |
| 3068 class C { | 3105 class C { |
| 3069 a.A m() { return null; } | 3106 a.A m() { return null; } |
| 3070 }''' | 3107 }''' |
| 3071 ], <ErrorCode>[ | 3108 ], <ErrorCode>[ |
| 3072 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3109 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3073 ]); | 3110 ]); |
| 3074 } | 3111 } |
| 3075 | 3112 |
| 3076 void test_typeAnnotationDeferredClass_simpleFormalParameter() { | 3113 test_typeAnnotationDeferredClass_simpleFormalParameter() async { |
| 3077 resolveWithErrors(<String>[ | 3114 await resolveWithErrors(<String>[ |
| 3078 r''' | 3115 r''' |
| 3079 library lib1; | 3116 library lib1; |
| 3080 class A {}''', | 3117 class A {}''', |
| 3081 r''' | 3118 r''' |
| 3082 library root; | 3119 library root; |
| 3083 import 'lib1.dart' deferred as a; | 3120 import 'lib1.dart' deferred as a; |
| 3084 f(a.A v) {}''' | 3121 f(a.A v) {}''' |
| 3085 ], <ErrorCode>[ | 3122 ], <ErrorCode>[ |
| 3086 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3123 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3087 ]); | 3124 ]); |
| 3088 } | 3125 } |
| 3089 | 3126 |
| 3090 void test_typeAnnotationDeferredClass_typeArgumentList() { | 3127 test_typeAnnotationDeferredClass_typeArgumentList() async { |
| 3091 resolveWithErrors(<String>[ | 3128 await resolveWithErrors(<String>[ |
| 3092 r''' | 3129 r''' |
| 3093 library lib1; | 3130 library lib1; |
| 3094 class A {}''', | 3131 class A {}''', |
| 3095 r''' | 3132 r''' |
| 3096 library root; | 3133 library root; |
| 3097 import 'lib1.dart' deferred as a; | 3134 import 'lib1.dart' deferred as a; |
| 3098 class C<E> {} | 3135 class C<E> {} |
| 3099 C<a.A> c;''' | 3136 C<a.A> c;''' |
| 3100 ], <ErrorCode>[ | 3137 ], <ErrorCode>[ |
| 3101 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3138 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3102 ]); | 3139 ]); |
| 3103 } | 3140 } |
| 3104 | 3141 |
| 3105 void test_typeAnnotationDeferredClass_typeArgumentList2() { | 3142 test_typeAnnotationDeferredClass_typeArgumentList2() async { |
| 3106 resolveWithErrors(<String>[ | 3143 await resolveWithErrors(<String>[ |
| 3107 r''' | 3144 r''' |
| 3108 library lib1; | 3145 library lib1; |
| 3109 class A {}''', | 3146 class A {}''', |
| 3110 r''' | 3147 r''' |
| 3111 library root; | 3148 library root; |
| 3112 import 'lib1.dart' deferred as a; | 3149 import 'lib1.dart' deferred as a; |
| 3113 class C<E, F> {} | 3150 class C<E, F> {} |
| 3114 C<a.A, a.A> c;''' | 3151 C<a.A, a.A> c;''' |
| 3115 ], <ErrorCode>[ | 3152 ], <ErrorCode>[ |
| 3116 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, | 3153 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, |
| 3117 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3154 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3118 ]); | 3155 ]); |
| 3119 } | 3156 } |
| 3120 | 3157 |
| 3121 void test_typeAnnotationDeferredClass_typeParameter_bound() { | 3158 test_typeAnnotationDeferredClass_typeParameter_bound() async { |
| 3122 resolveWithErrors(<String>[ | 3159 await resolveWithErrors(<String>[ |
| 3123 r''' | 3160 r''' |
| 3124 library lib1; | 3161 library lib1; |
| 3125 class A {}''', | 3162 class A {}''', |
| 3126 r''' | 3163 r''' |
| 3127 library root; | 3164 library root; |
| 3128 import 'lib1.dart' deferred as a; | 3165 import 'lib1.dart' deferred as a; |
| 3129 class C<E extends a.A> {}''' | 3166 class C<E extends a.A> {}''' |
| 3130 ], <ErrorCode>[ | 3167 ], <ErrorCode>[ |
| 3131 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3168 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3132 ]); | 3169 ]); |
| 3133 } | 3170 } |
| 3134 | 3171 |
| 3135 void test_typeAnnotationDeferredClass_variableDeclarationList() { | 3172 test_typeAnnotationDeferredClass_variableDeclarationList() async { |
| 3136 resolveWithErrors(<String>[ | 3173 await resolveWithErrors(<String>[ |
| 3137 r''' | 3174 r''' |
| 3138 library lib1; | 3175 library lib1; |
| 3139 class A {}''', | 3176 class A {}''', |
| 3140 r''' | 3177 r''' |
| 3141 library root; | 3178 library root; |
| 3142 import 'lib1.dart' deferred as a; | 3179 import 'lib1.dart' deferred as a; |
| 3143 a.A v;''' | 3180 a.A v;''' |
| 3144 ], <ErrorCode>[ | 3181 ], <ErrorCode>[ |
| 3145 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3182 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3146 ]); | 3183 ]); |
| 3147 } | 3184 } |
| 3148 | 3185 |
| 3149 void test_typeAnnotationGenericFunctionParameter_localFunction() { | 3186 test_typeAnnotationGenericFunctionParameter_localFunction() async { |
| 3150 Source source = addSource(r''' | 3187 Source source = addSource(r''' |
| 3151 class A { | 3188 class A { |
| 3152 void method() { | 3189 void method() { |
| 3153 T local<T>(Object t) { | 3190 T local<T>(Object t) { |
| 3154 return (t is T) ? t : null; | 3191 return (t is T) ? t : null; |
| 3155 } | 3192 } |
| 3156 } | 3193 } |
| 3157 }'''); | 3194 }'''); |
| 3158 assertErrors( | 3195 await assertErrors( |
| 3159 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); | 3196 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); |
| 3160 verify([source]); | 3197 verify([source]); |
| 3161 } | 3198 } |
| 3162 | 3199 |
| 3163 void test_typeAnnotationGenericFunctionParameter_method() { | 3200 test_typeAnnotationGenericFunctionParameter_method() async { |
| 3164 Source source = addSource(r''' | 3201 Source source = addSource(r''' |
| 3165 class A { | 3202 class A { |
| 3166 T method<T>(Object t) { | 3203 T method<T>(Object t) { |
| 3167 return (t is T) ? t : null; | 3204 return (t is T) ? t : null; |
| 3168 } | 3205 } |
| 3169 }'''); | 3206 }'''); |
| 3170 assertErrors( | 3207 await assertErrors( |
| 3171 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); | 3208 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); |
| 3172 verify([source]); | 3209 verify([source]); |
| 3173 } | 3210 } |
| 3174 | 3211 |
| 3175 void test_typeAnnotationGenericFunctionParameter_topLevelFunction() { | 3212 test_typeAnnotationGenericFunctionParameter_topLevelFunction() async { |
| 3176 Source source = addSource(r''' | 3213 Source source = addSource(r''' |
| 3177 T function<T>(Object t) { | 3214 T function<T>(Object t) { |
| 3178 return (t is T) ? t : null; | 3215 return (t is T) ? t : null; |
| 3179 }'''); | 3216 }'''); |
| 3180 assertErrors( | 3217 await assertErrors( |
| 3181 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); | 3218 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); |
| 3182 verify([source]); | 3219 verify([source]); |
| 3183 } | 3220 } |
| 3184 | 3221 |
| 3185 void test_typeParameterReferencedByStatic_field() { | 3222 test_typeParameterReferencedByStatic_field() async { |
| 3186 Source source = addSource(r''' | 3223 Source source = addSource(r''' |
| 3187 class A<K> { | 3224 class A<K> { |
| 3188 static K k; | 3225 static K k; |
| 3189 }'''); | 3226 }'''); |
| 3190 assertErrors( | 3227 await assertErrors( |
| 3191 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); | 3228 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 3192 verify([source]); | 3229 verify([source]); |
| 3193 } | 3230 } |
| 3194 | 3231 |
| 3195 void test_typeParameterReferencedByStatic_getter() { | 3232 test_typeParameterReferencedByStatic_getter() async { |
| 3196 Source source = addSource(r''' | 3233 Source source = addSource(r''' |
| 3197 class A<K> { | 3234 class A<K> { |
| 3198 static K get k => null; | 3235 static K get k => null; |
| 3199 }'''); | 3236 }'''); |
| 3200 assertErrors( | 3237 await assertErrors( |
| 3201 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); | 3238 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 3202 verify([source]); | 3239 verify([source]); |
| 3203 } | 3240 } |
| 3204 | 3241 |
| 3205 void test_typeParameterReferencedByStatic_methodBodyReference() { | 3242 test_typeParameterReferencedByStatic_methodBodyReference() async { |
| 3206 Source source = addSource(r''' | 3243 Source source = addSource(r''' |
| 3207 class A<K> { | 3244 class A<K> { |
| 3208 static m() { | 3245 static m() { |
| 3209 K k; | 3246 K k; |
| 3210 } | 3247 } |
| 3211 }'''); | 3248 }'''); |
| 3212 assertErrors( | 3249 await assertErrors( |
| 3213 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); | 3250 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 3214 verify([source]); | 3251 verify([source]); |
| 3215 } | 3252 } |
| 3216 | 3253 |
| 3217 void test_typeParameterReferencedByStatic_methodParameter() { | 3254 test_typeParameterReferencedByStatic_methodParameter() async { |
| 3218 Source source = addSource(r''' | 3255 Source source = addSource(r''' |
| 3219 class A<K> { | 3256 class A<K> { |
| 3220 static m(K k) {} | 3257 static m(K k) {} |
| 3221 }'''); | 3258 }'''); |
| 3222 assertErrors( | 3259 await assertErrors( |
| 3223 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); | 3260 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 3224 verify([source]); | 3261 verify([source]); |
| 3225 } | 3262 } |
| 3226 | 3263 |
| 3227 void test_typeParameterReferencedByStatic_methodReturn() { | 3264 test_typeParameterReferencedByStatic_methodReturn() async { |
| 3228 Source source = addSource(r''' | 3265 Source source = addSource(r''' |
| 3229 class A<K> { | 3266 class A<K> { |
| 3230 static K m() { return null; } | 3267 static K m() { return null; } |
| 3231 }'''); | 3268 }'''); |
| 3232 assertErrors( | 3269 await assertErrors( |
| 3233 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); | 3270 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 3234 verify([source]); | 3271 verify([source]); |
| 3235 } | 3272 } |
| 3236 | 3273 |
| 3237 void test_typeParameterReferencedByStatic_setter() { | 3274 test_typeParameterReferencedByStatic_setter() async { |
| 3238 Source source = addSource(r''' | 3275 Source source = addSource(r''' |
| 3239 class A<K> { | 3276 class A<K> { |
| 3240 static set s(K k) {} | 3277 static set s(K k) {} |
| 3241 }'''); | 3278 }'''); |
| 3242 assertErrors( | 3279 await assertErrors( |
| 3243 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); | 3280 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 3244 verify([source]); | 3281 verify([source]); |
| 3245 } | 3282 } |
| 3246 | 3283 |
| 3247 void test_typePromotion_functionType_arg_InterToDyn() { | 3284 test_typePromotion_functionType_arg_InterToDyn() async { |
| 3248 Source source = addSource(r''' | 3285 Source source = addSource(r''' |
| 3249 typedef FuncDyn(x); | 3286 typedef FuncDyn(x); |
| 3250 typedef FuncA(A a); | 3287 typedef FuncA(A a); |
| 3251 class A {} | 3288 class A {} |
| 3252 class B {} | 3289 class B {} |
| 3253 main(FuncA f) { | 3290 main(FuncA f) { |
| 3254 if (f is FuncDyn) { | 3291 if (f is FuncDyn) { |
| 3255 f(new B()); | 3292 f(new B()); |
| 3256 } | 3293 } |
| 3257 }'''); | 3294 }'''); |
| 3258 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 3295 await assertErrors( |
| 3296 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 3259 } | 3297 } |
| 3260 | 3298 |
| 3261 void test_typeTestNonType() { | 3299 test_typeTestNonType() async { |
| 3262 Source source = addSource(r''' | 3300 Source source = addSource(r''' |
| 3263 var A = 0; | 3301 var A = 0; |
| 3264 f(var p) { | 3302 f(var p) { |
| 3265 if (p is A) { | 3303 if (p is A) { |
| 3266 } | 3304 } |
| 3267 }'''); | 3305 }'''); |
| 3268 assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_NON_TYPE]); | 3306 await assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_NON_TYPE]); |
| 3269 verify([source]); | 3307 verify([source]); |
| 3270 } | 3308 } |
| 3271 | 3309 |
| 3272 void test_typeTestWithUndefinedName() { | 3310 test_typeTestWithUndefinedName() async { |
| 3273 Source source = addSource(r''' | 3311 Source source = addSource(r''' |
| 3274 f(var p) { | 3312 f(var p) { |
| 3275 if (p is A) { | 3313 if (p is A) { |
| 3276 } | 3314 } |
| 3277 }'''); | 3315 }'''); |
| 3278 assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME]); | 3316 await assertErrors( |
| 3317 source, [StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME]); |
| 3279 verify([source]); | 3318 verify([source]); |
| 3280 } | 3319 } |
| 3281 | 3320 |
| 3282 void test_undefinedClass_instanceCreation() { | 3321 test_undefinedClass_instanceCreation() async { |
| 3283 Source source = addSource("f() { new C(); }"); | 3322 Source source = addSource("f() { new C(); }"); |
| 3284 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); | 3323 await assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); |
| 3285 } | 3324 } |
| 3286 | 3325 |
| 3287 void test_undefinedClass_variableDeclaration() { | 3326 test_undefinedClass_variableDeclaration() async { |
| 3288 Source source = addSource("f() { C c; }"); | 3327 Source source = addSource("f() { C c; }"); |
| 3289 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); | 3328 await assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); |
| 3290 } | 3329 } |
| 3291 | 3330 |
| 3292 void test_undefinedClassBoolean_variableDeclaration() { | 3331 test_undefinedClassBoolean_variableDeclaration() async { |
| 3293 Source source = addSource("f() { boolean v; }"); | 3332 Source source = addSource("f() { boolean v; }"); |
| 3294 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS_BOOLEAN]); | 3333 await assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS_BOOLEAN]); |
| 3295 } | 3334 } |
| 3296 | 3335 |
| 3297 void test_undefinedGetter_fromLibrary() { | 3336 test_undefinedGetter_fromLibrary() async { |
| 3298 Source source1 = addNamedSource("/lib.dart", ""); | 3337 Source source1 = addNamedSource("/lib.dart", ""); |
| 3299 Source source2 = addNamedSource( | 3338 Source source2 = addNamedSource( |
| 3300 "/lib2.dart", | 3339 "/lib2.dart", |
| 3301 r''' | 3340 r''' |
| 3302 import 'lib.dart' as lib; | 3341 import 'lib.dart' as lib; |
| 3303 void f() { | 3342 void f() { |
| 3304 var g = lib.gg; | 3343 var g = lib.gg; |
| 3305 }'''); | 3344 }'''); |
| 3306 assertErrors(source2, [StaticWarningCode.UNDEFINED_GETTER]); | 3345 await assertErrors(source2, [StaticWarningCode.UNDEFINED_GETTER]); |
| 3307 verify([source1]); | 3346 verify([source1]); |
| 3308 } | 3347 } |
| 3309 | 3348 |
| 3310 void test_undefinedIdentifier_for() { | 3349 test_undefinedIdentifier_for() async { |
| 3311 Source source = addSource(r''' | 3350 Source source = addSource(r''' |
| 3312 f(var l) { | 3351 f(var l) { |
| 3313 for (e in l) { | 3352 for (e in l) { |
| 3314 } | 3353 } |
| 3315 }'''); | 3354 }'''); |
| 3316 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3355 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3317 } | 3356 } |
| 3318 | 3357 |
| 3319 void test_undefinedIdentifier_function() { | 3358 test_undefinedIdentifier_function() async { |
| 3320 Source source = addSource("int a() => b;"); | 3359 Source source = addSource("int a() => b;"); |
| 3321 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3360 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3322 } | 3361 } |
| 3323 | 3362 |
| 3324 void test_undefinedIdentifier_importCore_withShow() { | 3363 test_undefinedIdentifier_importCore_withShow() async { |
| 3325 Source source = addSource(r''' | 3364 Source source = addSource(r''' |
| 3326 import 'dart:core' show List; | 3365 import 'dart:core' show List; |
| 3327 main() { | 3366 main() { |
| 3328 List; | 3367 List; |
| 3329 String; | 3368 String; |
| 3330 }'''); | 3369 }'''); |
| 3331 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3370 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3332 } | 3371 } |
| 3333 | 3372 |
| 3334 void test_undefinedIdentifier_initializer() { | 3373 test_undefinedIdentifier_initializer() async { |
| 3335 Source source = addSource("var a = b;"); | 3374 Source source = addSource("var a = b;"); |
| 3336 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3375 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3337 } | 3376 } |
| 3338 | 3377 |
| 3339 void test_undefinedIdentifier_methodInvocation() { | 3378 test_undefinedIdentifier_methodInvocation() async { |
| 3340 Source source = addSource("f() { C.m(); }"); | 3379 Source source = addSource("f() { C.m(); }"); |
| 3341 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3380 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3342 } | 3381 } |
| 3343 | 3382 |
| 3344 void test_undefinedIdentifier_private_getter() { | 3383 test_undefinedIdentifier_private_getter() async { |
| 3345 addNamedSource( | 3384 addNamedSource( |
| 3346 "/lib.dart", | 3385 "/lib.dart", |
| 3347 r''' | 3386 r''' |
| 3348 library lib; | 3387 library lib; |
| 3349 class A { | 3388 class A { |
| 3350 var _foo; | 3389 var _foo; |
| 3351 }'''); | 3390 }'''); |
| 3352 Source source = addSource(r''' | 3391 Source source = addSource(r''' |
| 3353 import 'lib.dart'; | 3392 import 'lib.dart'; |
| 3354 class B extends A { | 3393 class B extends A { |
| 3355 test() { | 3394 test() { |
| 3356 var v = _foo; | 3395 var v = _foo; |
| 3357 } | 3396 } |
| 3358 }'''); | 3397 }'''); |
| 3359 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3398 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3360 } | 3399 } |
| 3361 | 3400 |
| 3362 void test_undefinedIdentifier_private_setter() { | 3401 test_undefinedIdentifier_private_setter() async { |
| 3363 addNamedSource( | 3402 addNamedSource( |
| 3364 "/lib.dart", | 3403 "/lib.dart", |
| 3365 r''' | 3404 r''' |
| 3366 library lib; | 3405 library lib; |
| 3367 class A { | 3406 class A { |
| 3368 var _foo; | 3407 var _foo; |
| 3369 }'''); | 3408 }'''); |
| 3370 Source source = addSource(r''' | 3409 Source source = addSource(r''' |
| 3371 import 'lib.dart'; | 3410 import 'lib.dart'; |
| 3372 class B extends A { | 3411 class B extends A { |
| 3373 test() { | 3412 test() { |
| 3374 _foo = 42; | 3413 _foo = 42; |
| 3375 } | 3414 } |
| 3376 }'''); | 3415 }'''); |
| 3377 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); | 3416 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3378 } | 3417 } |
| 3379 | 3418 |
| 3380 void test_undefinedIdentifierAwait_function() { | 3419 test_undefinedIdentifierAwait_function() async { |
| 3381 Source source = addSource("void a() { await; }"); | 3420 Source source = addSource("void a() { await; }"); |
| 3382 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT]); | 3421 await assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT]); |
| 3383 } | 3422 } |
| 3384 | 3423 |
| 3385 void test_undefinedNamedParameter() { | 3424 test_undefinedNamedParameter() async { |
| 3386 Source source = addSource(r''' | 3425 Source source = addSource(r''' |
| 3387 f({a, b}) {} | 3426 f({a, b}) {} |
| 3388 main() { | 3427 main() { |
| 3389 f(c: 1); | 3428 f(c: 1); |
| 3390 }'''); | 3429 }'''); |
| 3391 assertErrors(source, [StaticWarningCode.UNDEFINED_NAMED_PARAMETER]); | 3430 await assertErrors(source, [StaticWarningCode.UNDEFINED_NAMED_PARAMETER]); |
| 3392 // no verify(), 'c' is not resolved | 3431 // no verify(), 'c' is not resolved |
| 3393 } | 3432 } |
| 3394 | 3433 |
| 3395 void test_undefinedSetter() { | 3434 test_undefinedSetter() async { |
| 3396 addNamedSource("/lib.dart", ""); | 3435 addNamedSource("/lib.dart", ""); |
| 3397 Source source2 = addNamedSource( | 3436 Source source2 = addNamedSource( |
| 3398 "/lib2.dart", | 3437 "/lib2.dart", |
| 3399 r''' | 3438 r''' |
| 3400 import 'lib.dart' as lib; | 3439 import 'lib.dart' as lib; |
| 3401 void f() { | 3440 void f() { |
| 3402 lib.gg = null; | 3441 lib.gg = null; |
| 3403 }'''); | 3442 }'''); |
| 3404 assertErrors(source2, [StaticWarningCode.UNDEFINED_SETTER]); | 3443 await assertErrors(source2, [StaticWarningCode.UNDEFINED_SETTER]); |
| 3405 } | 3444 } |
| 3406 | 3445 |
| 3407 void test_undefinedStaticMethodOrGetter_getter() { | 3446 test_undefinedStaticMethodOrGetter_getter() async { |
| 3408 Source source = addSource(r''' | 3447 Source source = addSource(r''' |
| 3409 class C {} | 3448 class C {} |
| 3410 f(var p) { | 3449 f(var p) { |
| 3411 f(C.m); | 3450 f(C.m); |
| 3412 }'''); | 3451 }'''); |
| 3413 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); | 3452 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); |
| 3414 } | 3453 } |
| 3415 | 3454 |
| 3416 void test_undefinedStaticMethodOrGetter_getter_inSuperclass() { | 3455 test_undefinedStaticMethodOrGetter_getter_inSuperclass() async { |
| 3417 Source source = addSource(r''' | 3456 Source source = addSource(r''' |
| 3418 class S { | 3457 class S { |
| 3419 static int get g => 0; | 3458 static int get g => 0; |
| 3420 } | 3459 } |
| 3421 class C extends S {} | 3460 class C extends S {} |
| 3422 f(var p) { | 3461 f(var p) { |
| 3423 f(C.g); | 3462 f(C.g); |
| 3424 }'''); | 3463 }'''); |
| 3425 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); | 3464 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); |
| 3426 } | 3465 } |
| 3427 | 3466 |
| 3428 void test_undefinedStaticMethodOrGetter_method() { | 3467 test_undefinedStaticMethodOrGetter_method() async { |
| 3429 Source source = addSource(r''' | 3468 Source source = addSource(r''' |
| 3430 class C {} | 3469 class C {} |
| 3431 f(var p) { | 3470 f(var p) { |
| 3432 f(C.m()); | 3471 f(C.m()); |
| 3433 }'''); | 3472 }'''); |
| 3434 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); | 3473 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 3435 } | 3474 } |
| 3436 | 3475 |
| 3437 void test_undefinedStaticMethodOrGetter_method_inSuperclass() { | 3476 test_undefinedStaticMethodOrGetter_method_inSuperclass() async { |
| 3438 Source source = addSource(r''' | 3477 Source source = addSource(r''' |
| 3439 class S { | 3478 class S { |
| 3440 static m() {} | 3479 static m() {} |
| 3441 } | 3480 } |
| 3442 class C extends S {} | 3481 class C extends S {} |
| 3443 f(var p) { | 3482 f(var p) { |
| 3444 f(C.m()); | 3483 f(C.m()); |
| 3445 }'''); | 3484 }'''); |
| 3446 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); | 3485 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 3447 } | 3486 } |
| 3448 | 3487 |
| 3449 void test_undefinedStaticMethodOrGetter_setter_inSuperclass() { | 3488 test_undefinedStaticMethodOrGetter_setter_inSuperclass() async { |
| 3450 Source source = addSource(r''' | 3489 Source source = addSource(r''' |
| 3451 class S { | 3490 class S { |
| 3452 static set s(int i) {} | 3491 static set s(int i) {} |
| 3453 } | 3492 } |
| 3454 class C extends S {} | 3493 class C extends S {} |
| 3455 f(var p) { | 3494 f(var p) { |
| 3456 f(C.s = 1); | 3495 f(C.s = 1); |
| 3457 }'''); | 3496 }'''); |
| 3458 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); | 3497 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); |
| 3459 } | 3498 } |
| 3460 | 3499 |
| 3461 void test_voidReturnForGetter() { | 3500 test_voidReturnForGetter() async { |
| 3462 Source source = addSource(r''' | 3501 Source source = addSource(r''' |
| 3463 class S { | 3502 class S { |
| 3464 void get value {} | 3503 void get value {} |
| 3465 }'''); | 3504 }'''); |
| 3466 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); | 3505 await assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); |
| 3467 } | 3506 } |
| 3468 } | 3507 } |
| OLD | NEW |