OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library engine.compile_time_error_code_test; |
| 6 |
| 7 import 'package:analyzer/src/generated/source_io.dart'; |
| 8 import 'package:analyzer/src/generated/error.dart'; |
| 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:unittest/unittest.dart' as _ut; |
| 12 import 'resolver_test.dart'; |
| 13 import 'test_support.dart'; |
| 14 import '../reflective_tests.dart'; |
| 15 |
| 16 |
| 17 class CompileTimeErrorCodeTest extends ResolverTestCase { |
| 18 void fail_compileTimeConstantRaisesException() { |
| 19 Source source = addSource(EngineTestCase.createSource([])); |
| 20 resolve(source); |
| 21 assertErrors(source, [CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCE
PTION]); |
| 22 verify([source]); |
| 23 } |
| 24 |
| 25 void fail_constEvalThrowsException() { |
| 26 Source source = addSource(EngineTestCase.createSource([ |
| 27 "class C {", |
| 28 " const C();", |
| 29 "}", |
| 30 "f() { return const C(); }"])); |
| 31 resolve(source); |
| 32 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTIO
N]); |
| 33 verify([source]); |
| 34 } |
| 35 |
| 36 void fail_invalidIdentifierInAsync_async() { |
| 37 // TODO(brianwilkerson) Report this error. |
| 38 resetWithAsync(); |
| 39 Source source = addSource(EngineTestCase.createSource([ |
| 40 "class A {", |
| 41 " m() async {", |
| 42 " int async;", |
| 43 " }", |
| 44 "}"])); |
| 45 resolve(source); |
| 46 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); |
| 47 verify([source]); |
| 48 } |
| 49 |
| 50 void fail_invalidIdentifierInAsync_await() { |
| 51 // TODO(brianwilkerson) Report this error. |
| 52 resetWithAsync(); |
| 53 Source source = addSource(EngineTestCase.createSource([ |
| 54 "class A {", |
| 55 " m() async {", |
| 56 " int await;", |
| 57 " }", |
| 58 "}"])); |
| 59 resolve(source); |
| 60 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); |
| 61 verify([source]); |
| 62 } |
| 63 |
| 64 void fail_invalidIdentifierInAsync_yield() { |
| 65 // TODO(brianwilkerson) Report this error. |
| 66 resetWithAsync(); |
| 67 Source source = addSource(EngineTestCase.createSource([ |
| 68 "class A {", |
| 69 " m() async {", |
| 70 " int yield;", |
| 71 " }", |
| 72 "}"])); |
| 73 resolve(source); |
| 74 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); |
| 75 verify([source]); |
| 76 } |
| 77 |
| 78 void fail_mixinDeclaresConstructor() { |
| 79 Source source = addSource(EngineTestCase.createSource([ |
| 80 "class A {", |
| 81 " A() {}", |
| 82 "}", |
| 83 "class B extends Object mixin A {}"])); |
| 84 resolve(source); |
| 85 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
| 86 verify([source]); |
| 87 } |
| 88 |
| 89 void fail_mixinOfNonClass() { |
| 90 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS. |
| 91 Source source = addSource(EngineTestCase.createSource(["var A;", "class B ex
tends Object mixin A {}"])); |
| 92 resolve(source); |
| 93 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
| 94 verify([source]); |
| 95 } |
| 96 |
| 97 void fail_objectCannotExtendAnotherClass() { |
| 98 Source source = addSource(EngineTestCase.createSource([])); |
| 99 resolve(source); |
| 100 assertErrors(source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLAS
S]); |
| 101 verify([source]); |
| 102 } |
| 103 |
| 104 void fail_recursiveCompileTimeConstant() { |
| 105 Source source = addSource(EngineTestCase.createSource([ |
| 106 "class A {", |
| 107 " const A();", |
| 108 " final m = const A();", |
| 109 "}"])); |
| 110 resolve(source); |
| 111 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT])
; |
| 112 verify([source]); |
| 113 } |
| 114 |
| 115 void fail_recursiveCompileTimeConstant_cycle() { |
| 116 Source source = addSource(EngineTestCase.createSource(["const x = y + 1;", "
const y = x + 1;"])); |
| 117 resolve(source); |
| 118 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT])
; |
| 119 verify([source]); |
| 120 } |
| 121 |
| 122 void fail_superInitializerInObject() { |
| 123 Source source = addSource(EngineTestCase.createSource([])); |
| 124 resolve(source); |
| 125 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); |
| 126 verify([source]); |
| 127 } |
| 128 |
| 129 void fail_yieldEachInNonGenerator_async() { |
| 130 // TODO(brianwilkerson) We are currently parsing the yield statement as a bi
nary expression. |
| 131 resetWithAsync(); |
| 132 Source source = addSource(EngineTestCase.createSource(["f() async {", " yie
ld* 0;", "}"])); |
| 133 resolve(source); |
| 134 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); |
| 135 verify([source]); |
| 136 } |
| 137 |
| 138 void fail_yieldEachInNonGenerator_sync() { |
| 139 // TODO(brianwilkerson) We are currently parsing the yield statement as a bi
nary expression. |
| 140 resetWithAsync(); |
| 141 Source source = addSource(EngineTestCase.createSource(["f() {", " yield* 0;
", "}"])); |
| 142 resolve(source); |
| 143 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); |
| 144 verify([source]); |
| 145 } |
| 146 |
| 147 void fail_yieldInNonGenerator_async() { |
| 148 // TODO(brianwilkerson) We are currently trying to parse the yield statement
as a binary expression. |
| 149 resetWithAsync(); |
| 150 Source source = addSource(EngineTestCase.createSource(["f() async {", " yie
ld 0;", "}"])); |
| 151 resolve(source); |
| 152 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); |
| 153 verify([source]); |
| 154 } |
| 155 |
| 156 void fail_yieldInNonGenerator_sync() { |
| 157 // TODO(brianwilkerson) We are currently trying to parse the yield statement
as a binary expression. |
| 158 resetWithAsync(); |
| 159 Source source = addSource(EngineTestCase.createSource(["f() {", " yield 0;"
, "}"])); |
| 160 resolve(source); |
| 161 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); |
| 162 verify([source]); |
| 163 } |
| 164 |
| 165 void test_accessPrivateEnumField() { |
| 166 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 167 analysisOptions.enableEnum = true; |
| 168 resetWithOptions(analysisOptions); |
| 169 Source source = addSource(EngineTestCase.createSource([ |
| 170 "enum E { ONE }", |
| 171 "String name(E e) {", |
| 172 " return e._name;", |
| 173 "}"])); |
| 174 resolve(source); |
| 175 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); |
| 176 // Cannot verify because "_name" cannot be resolved. |
| 177 } |
| 178 |
| 179 void test_ambiguousExport() { |
| 180 Source source = addSource(EngineTestCase.createSource([ |
| 181 "library L;", |
| 182 "export 'lib1.dart';", |
| 183 "export 'lib2.dart';"])); |
| 184 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class N {}"])); |
| 185 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", "
class N {}"])); |
| 186 resolve(source); |
| 187 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); |
| 188 verify([source]); |
| 189 } |
| 190 |
| 191 void test_asyncForInWrongContext() { |
| 192 Source source = addSource(EngineTestCase.createSource(["f(list) {", " await
for (var e in list) {", " }", "}"])); |
| 193 resolve(source); |
| 194 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); |
| 195 verify([source]); |
| 196 } |
| 197 |
| 198 void test_awaitInWrongContext_sync() { |
| 199 resetWithAsync(); |
| 200 Source source = addSource(EngineTestCase.createSource(["f(x) {", " return a
wait x;", "}"])); |
| 201 resolve(source); |
| 202 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); |
| 203 verify([source]); |
| 204 } |
| 205 |
| 206 void test_awaitInWrongContext_syncStar() { |
| 207 resetWithAsync(); |
| 208 Source source = addSource(EngineTestCase.createSource(["f(x) sync* {", " yi
eld await x;", "}"])); |
| 209 resolve(source); |
| 210 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); |
| 211 verify([source]); |
| 212 } |
| 213 |
| 214 void test_builtInIdentifierAsMixinName_classTypeAlias() { |
| 215 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
B {}", "class as = A with B;"])); |
| 216 resolve(source); |
| 217 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NA
ME]); |
| 218 verify([source]); |
| 219 } |
| 220 |
| 221 void test_builtInIdentifierAsType_formalParameter_field() { |
| 222 Source source = addSource(EngineTestCase.createSource(["class A {", " var x
;", " A(static this.x);", "}"])); |
| 223 resolve(source); |
| 224 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); |
| 225 verify([source]); |
| 226 } |
| 227 |
| 228 void test_builtInIdentifierAsType_formalParameter_simple() { |
| 229 Source source = addSource(EngineTestCase.createSource(["f(static x) {", "}"]
)); |
| 230 resolve(source); |
| 231 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); |
| 232 verify([source]); |
| 233 } |
| 234 |
| 235 void test_builtInIdentifierAsType_variableDeclaration() { |
| 236 Source source = addSource(EngineTestCase.createSource(["f() {", " typedef x
;", "}"])); |
| 237 resolve(source); |
| 238 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); |
| 239 verify([source]); |
| 240 } |
| 241 |
| 242 void test_builtInIdentifierAsTypedefName_functionTypeAlias() { |
| 243 Source source = addSource(EngineTestCase.createSource(["typedef bool as();"]
)); |
| 244 resolve(source); |
| 245 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NA
ME]); |
| 246 verify([source]); |
| 247 } |
| 248 |
| 249 void test_builtInIdentifierAsTypeName() { |
| 250 Source source = addSource(EngineTestCase.createSource(["class as {}"])); |
| 251 resolve(source); |
| 252 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]
); |
| 253 verify([source]); |
| 254 } |
| 255 |
| 256 void test_builtInIdentifierAsTypeParameterName() { |
| 257 Source source = addSource(EngineTestCase.createSource(["class A<as> {}"])); |
| 258 resolve(source); |
| 259 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAM
ETER_NAME]); |
| 260 verify([source]); |
| 261 } |
| 262 |
| 263 void test_caseExpressionTypeImplementsEquals() { |
| 264 Source source = addSource(EngineTestCase.createSource([ |
| 265 "class IntWrapper {", |
| 266 " final int value;", |
| 267 " const IntWrapper(this.value);", |
| 268 " bool operator ==(IntWrapper x) {", |
| 269 " return value == x.value;", |
| 270 " }", |
| 271 " get hashCode => value;", |
| 272 "}", |
| 273 "", |
| 274 "f(var a) {", |
| 275 " switch(a) {", |
| 276 " case(const IntWrapper(1)) : return 1;", |
| 277 " default: return 0;", |
| 278 " }", |
| 279 "}"])); |
| 280 resolve(source); |
| 281 assertErrors(source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_E
QUALS]); |
| 282 verify([source]); |
| 283 } |
| 284 |
| 285 void test_conflictingConstructorNameAndMember_field() { |
| 286 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " A.x() {}", "}"])); |
| 287 resolve(source); |
| 288 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_
FIELD]); |
| 289 verify([source]); |
| 290 } |
| 291 |
| 292 void test_conflictingConstructorNameAndMember_method() { |
| 293 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A.x();", " void x() {}", "}"])); |
| 294 resolve(source); |
| 295 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_
METHOD]); |
| 296 verify([source]); |
| 297 } |
| 298 |
| 299 void test_conflictingGetterAndMethod_field_method() { |
| 300 Source source = addSource(EngineTestCase.createSource([ |
| 301 "class A {", |
| 302 " final int m = 0;", |
| 303 "}", |
| 304 "class B extends A {", |
| 305 " m() {}", |
| 306 "}"])); |
| 307 resolve(source); |
| 308 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); |
| 309 verify([source]); |
| 310 } |
| 311 |
| 312 void test_conflictingGetterAndMethod_getter_method() { |
| 313 Source source = addSource(EngineTestCase.createSource([ |
| 314 "class A {", |
| 315 " get m => 0;", |
| 316 "}", |
| 317 "class B extends A {", |
| 318 " m() {}", |
| 319 "}"])); |
| 320 resolve(source); |
| 321 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); |
| 322 verify([source]); |
| 323 } |
| 324 |
| 325 void test_conflictingGetterAndMethod_method_field() { |
| 326 Source source = addSource(EngineTestCase.createSource([ |
| 327 "class A {", |
| 328 " m() {}", |
| 329 "}", |
| 330 "class B extends A {", |
| 331 " int m;", |
| 332 "}"])); |
| 333 resolve(source); |
| 334 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); |
| 335 verify([source]); |
| 336 } |
| 337 |
| 338 void test_conflictingGetterAndMethod_method_getter() { |
| 339 Source source = addSource(EngineTestCase.createSource([ |
| 340 "class A {", |
| 341 " m() {}", |
| 342 "}", |
| 343 "class B extends A {", |
| 344 " get m => 0;", |
| 345 "}"])); |
| 346 resolve(source); |
| 347 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); |
| 348 verify([source]); |
| 349 } |
| 350 |
| 351 void test_conflictingTypeVariableAndClass() { |
| 352 Source source = addSource(EngineTestCase.createSource(["class T<T> {", "}"])
); |
| 353 resolve(source); |
| 354 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLA
SS]); |
| 355 verify([source]); |
| 356 } |
| 357 |
| 358 void test_conflictingTypeVariableAndMember_field() { |
| 359 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " va
r T;", "}"])); |
| 360 resolve(source); |
| 361 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM
BER]); |
| 362 verify([source]); |
| 363 } |
| 364 |
| 365 void test_conflictingTypeVariableAndMember_getter() { |
| 366 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " ge
t T => null;", "}"])); |
| 367 resolve(source); |
| 368 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM
BER]); |
| 369 verify([source]); |
| 370 } |
| 371 |
| 372 void test_conflictingTypeVariableAndMember_method() { |
| 373 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " T(
) {}", "}"])); |
| 374 resolve(source); |
| 375 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM
BER]); |
| 376 verify([source]); |
| 377 } |
| 378 |
| 379 void test_conflictingTypeVariableAndMember_method_static() { |
| 380 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " st
atic T() {}", "}"])); |
| 381 resolve(source); |
| 382 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM
BER]); |
| 383 verify([source]); |
| 384 } |
| 385 |
| 386 void test_conflictingTypeVariableAndMember_setter() { |
| 387 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " se
t T(x) {}", "}"])); |
| 388 resolve(source); |
| 389 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM
BER]); |
| 390 verify([source]); |
| 391 } |
| 392 |
| 393 void test_consistentCaseExpressionTypes_dynamic() { |
| 394 // Even though A.S and S have a static type of "dynamic", we should see |
| 395 // that they match 'abc', because they are constant strings. |
| 396 Source source = addSource(EngineTestCase.createSource([ |
| 397 "class A {", |
| 398 " static const S = 'A.S';", |
| 399 "}", |
| 400 "", |
| 401 "const S = 'S';", |
| 402 "", |
| 403 "foo(var p) {", |
| 404 " switch (p) {", |
| 405 " case S:", |
| 406 " break;", |
| 407 " case A.S:", |
| 408 " break;", |
| 409 " case 'abc':", |
| 410 " break;", |
| 411 " }", |
| 412 "}"])); |
| 413 resolve(source); |
| 414 assertNoErrors(source); |
| 415 verify([source]); |
| 416 } |
| 417 |
| 418 void test_constConstructorWithFieldInitializedByNonConst() { |
| 419 Source source = addSource(EngineTestCase.createSource([ |
| 420 "class A {", |
| 421 " final int i = f();", |
| 422 " const A();", |
| 423 "}", |
| 424 "int f() {", |
| 425 " return 3;", |
| 426 "}"])); |
| 427 resolve(source); |
| 428 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INIT
IALIZED_BY_NON_CONST]); |
| 429 verify([source]); |
| 430 } |
| 431 |
| 432 void test_constConstructorWithFieldInitializedByNonConst_static() { |
| 433 Source source = addSource(EngineTestCase.createSource([ |
| 434 "class A {", |
| 435 " static final int i = f();", |
| 436 " const A();", |
| 437 "}", |
| 438 "int f() {", |
| 439 " return 3;", |
| 440 "}"])); |
| 441 resolve(source); |
| 442 assertNoErrors(source); |
| 443 verify([source]); |
| 444 } |
| 445 |
| 446 void test_constConstructorWithMixin() { |
| 447 Source source = addSource(EngineTestCase.createSource([ |
| 448 "class M {", |
| 449 "}", |
| 450 "class A extends Object with M {", |
| 451 " const A();", |
| 452 "}"])); |
| 453 resolve(source); |
| 454 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]); |
| 455 verify([source]); |
| 456 } |
| 457 |
| 458 void test_constConstructorWithNonConstSuper_explicit() { |
| 459 Source source = addSource(EngineTestCase.createSource([ |
| 460 "class A {", |
| 461 " A();", |
| 462 "}", |
| 463 "class B extends A {", |
| 464 " const B(): super();", |
| 465 "}"])); |
| 466 resolve(source); |
| 467 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_
SUPER]); |
| 468 verify([source]); |
| 469 } |
| 470 |
| 471 void test_constConstructorWithNonConstSuper_implicit() { |
| 472 Source source = addSource(EngineTestCase.createSource([ |
| 473 "class A {", |
| 474 " A();", |
| 475 "}", |
| 476 "class B extends A {", |
| 477 " const B();", |
| 478 "}"])); |
| 479 resolve(source); |
| 480 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_
SUPER]); |
| 481 verify([source]); |
| 482 } |
| 483 |
| 484 void test_constConstructorWithNonFinalField_mixin() { |
| 485 Source source = addSource(EngineTestCase.createSource([ |
| 486 "class A {", |
| 487 " var a;", |
| 488 "}", |
| 489 "class B extends Object with A {", |
| 490 " const B();", |
| 491 "}"])); |
| 492 resolve(source); |
| 493 assertErrors(source, [ |
| 494 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, |
| 495 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]); |
| 496 verify([source]); |
| 497 } |
| 498 |
| 499 void test_constConstructorWithNonFinalField_super() { |
| 500 Source source = addSource(EngineTestCase.createSource([ |
| 501 "class A {", |
| 502 " var a;", |
| 503 "}", |
| 504 "class B extends A {", |
| 505 " const B();", |
| 506 "}"])); |
| 507 resolve(source); |
| 508 assertErrors(source, [ |
| 509 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD, |
| 510 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); |
| 511 verify([source]); |
| 512 } |
| 513 |
| 514 void test_constConstructorWithNonFinalField_this() { |
| 515 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " const A();", "}"])); |
| 516 resolve(source); |
| 517 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_
FIELD]); |
| 518 verify([source]); |
| 519 } |
| 520 |
| 521 void test_constDeferredClass() { |
| 522 resolveWithAndWithoutExperimental(<String> [ |
| 523 EngineTestCase.createSource(["library lib1;", "class A {", " const A();
", "}"]), |
| 524 EngineTestCase.createSource([ |
| 525 "library root;", |
| 526 "import 'lib1.dart' deferred as a;", |
| 527 "main() {", |
| 528 " const a.A();", |
| 529 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.CONST_DEFERRED_CLASS]); |
| 530 } |
| 531 |
| 532 void test_constDeferredClass_namedConstructor() { |
| 533 resolveWithAndWithoutExperimental(<String> [ |
| 534 EngineTestCase.createSource(["library lib1;", "class A {", " const A.b(
);", "}"]), |
| 535 EngineTestCase.createSource([ |
| 536 "library root;", |
| 537 "import 'lib1.dart' deferred as a;", |
| 538 "main() {", |
| 539 " const a.A.b();", |
| 540 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.CONST_DEFERRED_CLASS]); |
| 541 } |
| 542 |
| 543 void test_constEval_newInstance_constConstructor() { |
| 544 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "const a = new A();"])); |
| 545 resolve(source); |
| 546 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA
NT_VALUE]); |
| 547 verify([source]); |
| 548 } |
| 549 |
| 550 void test_constEval_newInstance_externalFactoryConstConstructor() { |
| 551 // We can't evaluate "const A()" because its constructor is external. But |
| 552 // the code is correct--we shouldn't report an error. |
| 553 Source source = addSource(EngineTestCase.createSource([ |
| 554 "class A {", |
| 555 " external factory const A();", |
| 556 "}", |
| 557 "const x = const A();"])); |
| 558 resolve(source); |
| 559 assertNoErrors(source); |
| 560 verify([source]); |
| 561 } |
| 562 |
| 563 void test_constEval_propertyExtraction_targetNotConst() { |
| 564 Source source = addSource(EngineTestCase.createSource([ |
| 565 "class A {", |
| 566 " const A();", |
| 567 " m() {}", |
| 568 "}", |
| 569 "final a = const A();", |
| 570 "const C = a.m;"])); |
| 571 resolve(source); |
| 572 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA
NT_VALUE]); |
| 573 verify([source]); |
| 574 } |
| 575 |
| 576 void test_constEvalThrowsException_binaryMinus_null() { |
| 577 _check_constEvalThrowsException_binary_null("null - 5", false); |
| 578 _check_constEvalThrowsException_binary_null("5 - null", true); |
| 579 } |
| 580 |
| 581 void test_constEvalThrowsException_binaryPlus_null() { |
| 582 _check_constEvalThrowsException_binary_null("null + 5", false); |
| 583 _check_constEvalThrowsException_binary_null("5 + null", true); |
| 584 } |
| 585 |
| 586 void test_constEvalThrowsException_divisionByZero() { |
| 587 Source source = addSource("const C = 1 ~/ 0;"); |
| 588 resolve(source); |
| 589 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]); |
| 590 verify([source]); |
| 591 } |
| 592 |
| 593 void test_constEvalThrowsException_unaryBitNot_null() { |
| 594 Source source = addSource("const C = ~null;"); |
| 595 resolve(source); |
| 596 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 597 // no verify(), '~null' is not resolved |
| 598 } |
| 599 |
| 600 void test_constEvalThrowsException_unaryNegated_null() { |
| 601 Source source = addSource("const C = -null;"); |
| 602 resolve(source); |
| 603 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 604 // no verify(), '-null' is not resolved |
| 605 } |
| 606 |
| 607 void test_constEvalThrowsException_unaryNot_null() { |
| 608 Source source = addSource("const C = !null;"); |
| 609 resolve(source); |
| 610 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 611 verify([source]); |
| 612 } |
| 613 |
| 614 void test_constEvalTypeBool_binary() { |
| 615 _check_constEvalTypeBool_withParameter_binary("p && ''"); |
| 616 _check_constEvalTypeBool_withParameter_binary("p || ''"); |
| 617 } |
| 618 |
| 619 void test_constEvalTypeBool_binary_leftTrue() { |
| 620 Source source = addSource("const C = (true || 0);"); |
| 621 resolve(source); |
| 622 assertErrors(source, [ |
| 623 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
| 624 StaticTypeWarningCode.NON_BOOL_OPERAND, |
| 625 HintCode.DEAD_CODE]); |
| 626 verify([source]); |
| 627 } |
| 628 |
| 629 void test_constEvalTypeBoolNumString_equal() { |
| 630 Source source = addSource(EngineTestCase.createSource([ |
| 631 "class A {", |
| 632 " const A();", |
| 633 "}", |
| 634 "class B {", |
| 635 " final a;", |
| 636 " const B(num p) : a = p == const A();", |
| 637 "}"])); |
| 638 resolve(source); |
| 639 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING])
; |
| 640 verify([source]); |
| 641 } |
| 642 |
| 643 void test_constEvalTypeBoolNumString_notEqual() { |
| 644 Source source = addSource(EngineTestCase.createSource([ |
| 645 "class A {", |
| 646 " const A();", |
| 647 "}", |
| 648 "class B {", |
| 649 " final a;", |
| 650 " const B(String p) : a = p != const A();", |
| 651 "}"])); |
| 652 resolve(source); |
| 653 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING])
; |
| 654 verify([source]); |
| 655 } |
| 656 |
| 657 void test_constEvalTypeInt_binary() { |
| 658 _check_constEvalTypeInt_withParameter_binary("p ^ ''"); |
| 659 _check_constEvalTypeInt_withParameter_binary("p & ''"); |
| 660 _check_constEvalTypeInt_withParameter_binary("p | ''"); |
| 661 _check_constEvalTypeInt_withParameter_binary("p >> ''"); |
| 662 _check_constEvalTypeInt_withParameter_binary("p << ''"); |
| 663 } |
| 664 |
| 665 void test_constEvalTypeNum_binary() { |
| 666 _check_constEvalTypeNum_withParameter_binary("p + ''"); |
| 667 _check_constEvalTypeNum_withParameter_binary("p - ''"); |
| 668 _check_constEvalTypeNum_withParameter_binary("p * ''"); |
| 669 _check_constEvalTypeNum_withParameter_binary("p / ''"); |
| 670 _check_constEvalTypeNum_withParameter_binary("p ~/ ''"); |
| 671 _check_constEvalTypeNum_withParameter_binary("p > ''"); |
| 672 _check_constEvalTypeNum_withParameter_binary("p < ''"); |
| 673 _check_constEvalTypeNum_withParameter_binary("p >= ''"); |
| 674 _check_constEvalTypeNum_withParameter_binary("p <= ''"); |
| 675 _check_constEvalTypeNum_withParameter_binary("p % ''"); |
| 676 } |
| 677 |
| 678 void test_constFormalParameter_fieldFormalParameter() { |
| 679 Source source = addSource(EngineTestCase.createSource(["class A {", " var x
;", " A(const this.x) {}", "}"])); |
| 680 resolve(source); |
| 681 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); |
| 682 verify([source]); |
| 683 } |
| 684 |
| 685 void test_constFormalParameter_simpleFormalParameter() { |
| 686 Source source = addSource(EngineTestCase.createSource(["f(const x) {}"])); |
| 687 resolve(source); |
| 688 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); |
| 689 verify([source]); |
| 690 } |
| 691 |
| 692 void test_constInitializedWithNonConstValue() { |
| 693 Source source = addSource(EngineTestCase.createSource(["f(p) {", " const C
= p;", "}"])); |
| 694 resolve(source); |
| 695 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA
NT_VALUE]); |
| 696 verify([source]); |
| 697 } |
| 698 |
| 699 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { |
| 700 Source source = addSource("const List L = [0];"); |
| 701 resolve(source); |
| 702 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA
NT_VALUE]); |
| 703 verify([source]); |
| 704 } |
| 705 |
| 706 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { |
| 707 Source source = addSource("const Map M = {'a' : 0};"); |
| 708 resolve(source); |
| 709 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA
NT_VALUE]); |
| 710 verify([source]); |
| 711 } |
| 712 |
| 713 void test_constInitializedWithNonConstValueFromDeferredClass() { |
| 714 resolveWithAndWithoutExperimental(<String> [ |
| 715 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), |
| 716 EngineTestCase.createSource([ |
| 717 "library root;", |
| 718 "import 'lib1.dart' deferred as a;", |
| 719 "const B = a.V;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_S
UPPORTED], <ErrorCode> [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT
_VALUE_FROM_DEFERRED_LIBRARY]); |
| 720 } |
| 721 |
| 722 void test_constInitializedWithNonConstValueFromDeferredClass_nested() { |
| 723 resolveWithAndWithoutExperimental(<String> [ |
| 724 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), |
| 725 EngineTestCase.createSource([ |
| 726 "library root;", |
| 727 "import 'lib1.dart' deferred as a;", |
| 728 "const B = a.V + 1;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_N
OT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONS
TANT_VALUE_FROM_DEFERRED_LIBRARY]); |
| 729 } |
| 730 |
| 731 void test_constInstanceField() { |
| 732 Source source = addSource(EngineTestCase.createSource(["class C {", " const
int f = 0;", "}"])); |
| 733 resolve(source); |
| 734 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); |
| 735 verify([source]); |
| 736 } |
| 737 |
| 738 void test_constMapKeyTypeImplementsEquals_direct() { |
| 739 Source source = addSource(EngineTestCase.createSource([ |
| 740 "class A {", |
| 741 " const A();", |
| 742 " operator ==(other) => false;", |
| 743 "}", |
| 744 "main() {", |
| 745 " const {const A() : 0};", |
| 746 "}"])); |
| 747 resolve(source); |
| 748 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP
LEMENTS_EQUALS]); |
| 749 verify([source]); |
| 750 } |
| 751 |
| 752 void test_constMapKeyTypeImplementsEquals_dynamic() { |
| 753 // Note: static type of B.a is "dynamic", but actual type of the const |
| 754 // object is A. We need to make sure we examine the actual type when |
| 755 // deciding whether there is a problem with operator==. |
| 756 Source source = addSource(EngineTestCase.createSource([ |
| 757 "class A {", |
| 758 " const A();", |
| 759 " operator ==(other) => false;", |
| 760 "}", |
| 761 "class B {", |
| 762 " static const a = const A();", |
| 763 "}", |
| 764 "main() {", |
| 765 " const {B.a : 0};", |
| 766 "}"])); |
| 767 resolve(source); |
| 768 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP
LEMENTS_EQUALS]); |
| 769 verify([source]); |
| 770 } |
| 771 |
| 772 void test_constMapKeyTypeImplementsEquals_factory() { |
| 773 Source source = addSource(EngineTestCase.createSource([ |
| 774 "class A { const factory A() = B; }", |
| 775 "", |
| 776 "class B implements A {", |
| 777 " const B();", |
| 778 "", |
| 779 " operator ==(o) => true;", |
| 780 "}", |
| 781 "", |
| 782 "main() {", |
| 783 " var m = const { const A(): 42 };", |
| 784 "}"])); |
| 785 resolve(source); |
| 786 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP
LEMENTS_EQUALS]); |
| 787 verify([source]); |
| 788 } |
| 789 |
| 790 void test_constMapKeyTypeImplementsEquals_super() { |
| 791 Source source = addSource(EngineTestCase.createSource([ |
| 792 "class A {", |
| 793 " const A();", |
| 794 " operator ==(other) => false;", |
| 795 "}", |
| 796 "class B extends A {", |
| 797 " const B();", |
| 798 "}", |
| 799 "main() {", |
| 800 " const {const B() : 0};", |
| 801 "}"])); |
| 802 resolve(source); |
| 803 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP
LEMENTS_EQUALS]); |
| 804 verify([source]); |
| 805 } |
| 806 |
| 807 void test_constWithInvalidTypeParameters() { |
| 808 Source source = addSource(EngineTestCase.createSource([ |
| 809 "class A {", |
| 810 " const A();", |
| 811 "}", |
| 812 "f() { return const A<A>(); }"])); |
| 813 resolve(source); |
| 814 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER
S]); |
| 815 verify([source]); |
| 816 } |
| 817 |
| 818 void test_constWithInvalidTypeParameters_tooFew() { |
| 819 Source source = addSource(EngineTestCase.createSource([ |
| 820 "class A {}", |
| 821 "class C<K, V> {", |
| 822 " const C();", |
| 823 "}", |
| 824 "f(p) {", |
| 825 " return const C<A>();", |
| 826 "}"])); |
| 827 resolve(source); |
| 828 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER
S]); |
| 829 verify([source]); |
| 830 } |
| 831 |
| 832 void test_constWithInvalidTypeParameters_tooMany() { |
| 833 Source source = addSource(EngineTestCase.createSource([ |
| 834 "class A {}", |
| 835 "class C<E> {", |
| 836 " const C();", |
| 837 "}", |
| 838 "f(p) {", |
| 839 " return const C<A, A>();", |
| 840 "}"])); |
| 841 resolve(source); |
| 842 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER
S]); |
| 843 verify([source]); |
| 844 } |
| 845 |
| 846 void test_constWithNonConst() { |
| 847 Source source = addSource(EngineTestCase.createSource([ |
| 848 "class T {", |
| 849 " T(a, b, {c, d}) {}", |
| 850 "}", |
| 851 "f() { return const T(0, 1, c: 2, d: 3); }"])); |
| 852 resolve(source); |
| 853 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); |
| 854 verify([source]); |
| 855 } |
| 856 |
| 857 void test_constWithNonConstantArgument_annotation() { |
| 858 Source source = addSource(EngineTestCase.createSource([ |
| 859 "class A {", |
| 860 " const A(int p);", |
| 861 "}", |
| 862 "var v = 42;", |
| 863 "@A(v)", |
| 864 "main() {", |
| 865 "}"])); |
| 866 resolve(source); |
| 867 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]
); |
| 868 verify([source]); |
| 869 } |
| 870 |
| 871 void test_constWithNonConstantArgument_instanceCreation() { |
| 872 Source source = addSource(EngineTestCase.createSource([ |
| 873 "class A {", |
| 874 " const A(a);", |
| 875 "}", |
| 876 "f(p) { return const A(p); }"])); |
| 877 resolve(source); |
| 878 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]
); |
| 879 verify([source]); |
| 880 } |
| 881 |
| 882 void test_constWithNonType() { |
| 883 Source source = addSource(EngineTestCase.createSource(["int A;", "f() {", "
return const A();", "}"])); |
| 884 resolve(source); |
| 885 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); |
| 886 verify([source]); |
| 887 } |
| 888 |
| 889 void test_constWithNonType_fromLibrary() { |
| 890 Source source1 = addNamedSource("lib.dart", ""); |
| 891 Source source2 = addNamedSource("lib2.dart", EngineTestCase.createSource([ |
| 892 "import 'lib.dart' as lib;", |
| 893 "void f() {", |
| 894 " const lib.A();", |
| 895 "}"])); |
| 896 resolve(source1); |
| 897 resolve(source2); |
| 898 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); |
| 899 verify([source1]); |
| 900 } |
| 901 |
| 902 void test_constWithTypeParameters_direct() { |
| 903 Source source = addSource(EngineTestCase.createSource([ |
| 904 "class A<T> {", |
| 905 " static const V = const A<T>();", |
| 906 " const A();", |
| 907 "}"])); |
| 908 resolve(source); |
| 909 assertErrors(source, [ |
| 910 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, |
| 911 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 912 verify([source]); |
| 913 } |
| 914 |
| 915 void test_constWithTypeParameters_indirect() { |
| 916 Source source = addSource(EngineTestCase.createSource([ |
| 917 "class A<T> {", |
| 918 " static const V = const A<List<T>>();", |
| 919 " const A();", |
| 920 "}"])); |
| 921 resolve(source); |
| 922 assertErrors(source, [ |
| 923 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, |
| 924 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); |
| 925 verify([source]); |
| 926 } |
| 927 |
| 928 void test_constWithUndefinedConstructor() { |
| 929 Source source = addSource(EngineTestCase.createSource([ |
| 930 "class A {", |
| 931 " const A();", |
| 932 "}", |
| 933 "f() {", |
| 934 " return const A.noSuchConstructor();", |
| 935 "}"])); |
| 936 resolve(source); |
| 937 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]
); |
| 938 // no verify(), 'noSuchConstructor' is not resolved |
| 939 } |
| 940 |
| 941 void test_constWithUndefinedConstructorDefault() { |
| 942 Source source = addSource(EngineTestCase.createSource([ |
| 943 "class A {", |
| 944 " const A.name();", |
| 945 "}", |
| 946 "f() {", |
| 947 " return const A();", |
| 948 "}"])); |
| 949 resolve(source); |
| 950 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_
DEFAULT]); |
| 951 verify([source]); |
| 952 } |
| 953 |
| 954 void test_defaultValueInFunctionTypeAlias() { |
| 955 Source source = addSource(EngineTestCase.createSource(["typedef F([x = 0]);"
])); |
| 956 resolve(source); |
| 957 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_AL
IAS]); |
| 958 verify([source]); |
| 959 } |
| 960 |
| 961 void test_defaultValueInFunctionTypedParameter_named() { |
| 962 Source source = addSource(EngineTestCase.createSource(["f(g({p: null})) {}"]
)); |
| 963 resolve(source); |
| 964 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_P
ARAMETER]); |
| 965 verify([source]); |
| 966 } |
| 967 |
| 968 void test_defaultValueInFunctionTypedParameter_optional() { |
| 969 Source source = addSource(EngineTestCase.createSource(["f(g([p = null])) {}"
])); |
| 970 resolve(source); |
| 971 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_P
ARAMETER]); |
| 972 verify([source]); |
| 973 } |
| 974 |
| 975 void test_defaultValueInRedirectingFactoryConstructor() { |
| 976 Source source = addSource(EngineTestCase.createSource([ |
| 977 "class A {", |
| 978 " factory A([int x = 0]) = B;", |
| 979 "}", |
| 980 "", |
| 981 "class B implements A {", |
| 982 " B([int x = 1]) {}", |
| 983 "}"])); |
| 984 resolve(source); |
| 985 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACT
ORY_CONSTRUCTOR]); |
| 986 verify([source]); |
| 987 } |
| 988 |
| 989 void test_duplicateConstructorName_named() { |
| 990 Source source = addSource(EngineTestCase.createSource(["class A {", " A.a()
{}", " A.a() {}", "}"])); |
| 991 resolve(source); |
| 992 assertErrors(source, [ |
| 993 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, |
| 994 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME]); |
| 995 verify([source]); |
| 996 } |
| 997 |
| 998 void test_duplicateConstructorName_unnamed() { |
| 999 Source source = addSource(EngineTestCase.createSource(["class A {", " A() {
}", " A() {}", "}"])); |
| 1000 resolve(source); |
| 1001 assertErrors(source, [ |
| 1002 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, |
| 1003 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT]); |
| 1004 verify([source]); |
| 1005 } |
| 1006 |
| 1007 void test_duplicateDefinition() { |
| 1008 Source source = addSource(EngineTestCase.createSource(["f() {", " int m = 0
;", " m(a) {}", "}"])); |
| 1009 resolve(source); |
| 1010 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1011 verify([source]); |
| 1012 } |
| 1013 |
| 1014 void test_duplicateDefinition_acrossLibraries() { |
| 1015 Source librarySource = addNamedSource("/lib.dart", EngineTestCase.createSour
ce(["library lib;", "", "part 'a.dart';", "part 'b.dart';"])); |
| 1016 Source sourceA = addNamedSource("/a.dart", EngineTestCase.createSource(["par
t of lib;", "", "class A {}"])); |
| 1017 Source sourceB = addNamedSource("/b.dart", EngineTestCase.createSource(["par
t of lib;", "", "class A {}"])); |
| 1018 resolve(librarySource); |
| 1019 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1020 verify([librarySource, sourceA, sourceB]); |
| 1021 } |
| 1022 |
| 1023 void test_duplicateDefinition_classMembers_fields() { |
| 1024 Source source = addSource(EngineTestCase.createSource(["class A {", " int a
;", " int a;", "}"])); |
| 1025 resolve(source); |
| 1026 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1027 verify([source]); |
| 1028 } |
| 1029 |
| 1030 void test_duplicateDefinition_classMembers_fields_oneStatic() { |
| 1031 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " static int x;", "}"])); |
| 1032 resolve(source); |
| 1033 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1034 verify([source]); |
| 1035 } |
| 1036 |
| 1037 void test_duplicateDefinition_classMembers_methods() { |
| 1038 Source source = addSource(EngineTestCase.createSource(["class A {", " m() {
}", " m() {}", "}"])); |
| 1039 resolve(source); |
| 1040 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1041 verify([source]); |
| 1042 } |
| 1043 |
| 1044 void test_duplicateDefinition_localFields() { |
| 1045 Source source = addSource(EngineTestCase.createSource([ |
| 1046 "class A {", |
| 1047 " m() {", |
| 1048 " int a;", |
| 1049 " int a;", |
| 1050 " }", |
| 1051 "}"])); |
| 1052 resolve(source); |
| 1053 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1054 verify([source]); |
| 1055 } |
| 1056 |
| 1057 void test_duplicateDefinition_parameterWithFunctionName_local() { |
| 1058 Source source = addSource(EngineTestCase.createSource(["main() {", " f(f) {
}", "}"])); |
| 1059 resolve(source); |
| 1060 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1061 verify([source]); |
| 1062 } |
| 1063 |
| 1064 void test_duplicateDefinition_parameterWithFunctionName_topLevel() { |
| 1065 Source source = addSource(EngineTestCase.createSource(["main() {", " f(f) {
}", "}"])); |
| 1066 resolve(source); |
| 1067 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1068 verify([source]); |
| 1069 } |
| 1070 |
| 1071 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() { |
| 1072 Source source = addSource(EngineTestCase.createSource([ |
| 1073 "class A {", |
| 1074 " int get x => 0;", |
| 1075 "}", |
| 1076 "class B extends A {", |
| 1077 " static int get x => 0;", |
| 1078 "}"])); |
| 1079 resolve(source); |
| 1080 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]
); |
| 1081 verify([source]); |
| 1082 } |
| 1083 |
| 1084 void test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter()
{ |
| 1085 Source source = addSource(EngineTestCase.createSource([ |
| 1086 "abstract class A {", |
| 1087 " int get x;", |
| 1088 "}", |
| 1089 "class B extends A {", |
| 1090 " static int get x => 0;", |
| 1091 "}"])); |
| 1092 resolve(source); |
| 1093 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]
); |
| 1094 verify([source]); |
| 1095 } |
| 1096 |
| 1097 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() { |
| 1098 Source source = addSource(EngineTestCase.createSource([ |
| 1099 "class A {", |
| 1100 " x() {}", |
| 1101 "}", |
| 1102 "class B extends A {", |
| 1103 " static x() {}", |
| 1104 "}"])); |
| 1105 resolve(source); |
| 1106 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]
); |
| 1107 verify([source]); |
| 1108 } |
| 1109 |
| 1110 void test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod()
{ |
| 1111 Source source = addSource(EngineTestCase.createSource([ |
| 1112 "abstract class A {", |
| 1113 " x();", |
| 1114 "}", |
| 1115 "abstract class B extends A {", |
| 1116 " static x() {}", |
| 1117 "}"])); |
| 1118 resolve(source); |
| 1119 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]
); |
| 1120 verify([source]); |
| 1121 } |
| 1122 |
| 1123 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() { |
| 1124 Source source = addSource(EngineTestCase.createSource([ |
| 1125 "class A {", |
| 1126 " set x(value) {}", |
| 1127 "}", |
| 1128 "class B extends A {", |
| 1129 " static set x(value) {}", |
| 1130 "}"])); |
| 1131 resolve(source); |
| 1132 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]
); |
| 1133 verify([source]); |
| 1134 } |
| 1135 |
| 1136 void test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter()
{ |
| 1137 Source source = addSource(EngineTestCase.createSource([ |
| 1138 "abstract class A {", |
| 1139 " set x(value);", |
| 1140 "}", |
| 1141 "class B extends A {", |
| 1142 " static set x(value) {}", |
| 1143 "}"])); |
| 1144 resolve(source); |
| 1145 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]
); |
| 1146 verify([source]); |
| 1147 } |
| 1148 |
| 1149 void test_duplicateNamedArgument() { |
| 1150 Source source = addSource(EngineTestCase.createSource(["f({a, b}) {}", "main
() {", " f(a: 1, a: 2);", "}"])); |
| 1151 resolve(source); |
| 1152 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]); |
| 1153 verify([source]); |
| 1154 } |
| 1155 |
| 1156 void test_exportInternalLibrary() { |
| 1157 Source source = addSource(EngineTestCase.createSource(["export 'dart:_interc
eptors';"])); |
| 1158 resolve(source); |
| 1159 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]); |
| 1160 verify([source]); |
| 1161 } |
| 1162 |
| 1163 void test_exportOfNonLibrary() { |
| 1164 Source source = addSource(EngineTestCase.createSource(["library L;", "export
'lib1.dart';"])); |
| 1165 addNamedSource("/lib1.dart", EngineTestCase.createSource(["part of lib;"])); |
| 1166 resolve(source); |
| 1167 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
| 1168 verify([source]); |
| 1169 } |
| 1170 |
| 1171 void test_extendsDeferredClass() { |
| 1172 resolveWithAndWithoutExperimental(<String> [ |
| 1173 EngineTestCase.createSource(["library lib1;", "class A {}"]), |
| 1174 EngineTestCase.createSource([ |
| 1175 "library root;", |
| 1176 "import 'lib1.dart' deferred as a;", |
| 1177 "class B extends a.A {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPOR
TS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); |
| 1178 } |
| 1179 |
| 1180 void test_extendsDeferredClass_classTypeAlias() { |
| 1181 resolveWithAndWithoutExperimental(<String> [ |
| 1182 EngineTestCase.createSource(["library lib1;", "class A {}"]), |
| 1183 EngineTestCase.createSource([ |
| 1184 "library root;", |
| 1185 "import 'lib1.dart' deferred as a;", |
| 1186 "class M {}", |
| 1187 "class C = a.A with M;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORT
S_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); |
| 1188 } |
| 1189 |
| 1190 void test_extendsDisallowedClass_class_bool() { |
| 1191 Source source = addSource(EngineTestCase.createSource(["class A extends bool
{}"])); |
| 1192 resolve(source); |
| 1193 assertErrors(source, [ |
| 1194 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1195 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
| 1196 verify([source]); |
| 1197 } |
| 1198 |
| 1199 void test_extendsDisallowedClass_class_double() { |
| 1200 Source source = addSource(EngineTestCase.createSource(["class A extends doub
le {}"])); |
| 1201 resolve(source); |
| 1202 assertErrors(source, [ |
| 1203 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1204 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
| 1205 verify([source]); |
| 1206 } |
| 1207 |
| 1208 void test_extendsDisallowedClass_class_int() { |
| 1209 Source source = addSource(EngineTestCase.createSource(["class A extends int
{}"])); |
| 1210 resolve(source); |
| 1211 assertErrors(source, [ |
| 1212 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1213 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
| 1214 verify([source]); |
| 1215 } |
| 1216 |
| 1217 void test_extendsDisallowedClass_class_Null() { |
| 1218 Source source = addSource(EngineTestCase.createSource(["class A extends Null
{}"])); |
| 1219 resolve(source); |
| 1220 assertErrors(source, [ |
| 1221 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1222 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
| 1223 verify([source]); |
| 1224 } |
| 1225 |
| 1226 void test_extendsDisallowedClass_class_num() { |
| 1227 Source source = addSource(EngineTestCase.createSource(["class A extends num
{}"])); |
| 1228 resolve(source); |
| 1229 assertErrors(source, [ |
| 1230 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1231 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
| 1232 verify([source]); |
| 1233 } |
| 1234 |
| 1235 void test_extendsDisallowedClass_class_String() { |
| 1236 Source source = addSource(EngineTestCase.createSource(["class A extends Stri
ng {}"])); |
| 1237 resolve(source); |
| 1238 assertErrors(source, [ |
| 1239 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1240 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
| 1241 verify([source]); |
| 1242 } |
| 1243 |
| 1244 void test_extendsDisallowedClass_classTypeAlias_bool() { |
| 1245 Source source = addSource(EngineTestCase.createSource(["class M {}", "class
C = bool with M;"])); |
| 1246 resolve(source); |
| 1247 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
| 1248 verify([source]); |
| 1249 } |
| 1250 |
| 1251 void test_extendsDisallowedClass_classTypeAlias_double() { |
| 1252 Source source = addSource(EngineTestCase.createSource(["class M {}", "class
C = double with M;"])); |
| 1253 resolve(source); |
| 1254 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
| 1255 verify([source]); |
| 1256 } |
| 1257 |
| 1258 void test_extendsDisallowedClass_classTypeAlias_int() { |
| 1259 Source source = addSource(EngineTestCase.createSource(["class M {}", "class
C = int with M;"])); |
| 1260 resolve(source); |
| 1261 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
| 1262 verify([source]); |
| 1263 } |
| 1264 |
| 1265 void test_extendsDisallowedClass_classTypeAlias_Null() { |
| 1266 Source source = addSource(EngineTestCase.createSource(["class M {}", "class
C = Null with M;"])); |
| 1267 resolve(source); |
| 1268 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
| 1269 verify([source]); |
| 1270 } |
| 1271 |
| 1272 void test_extendsDisallowedClass_classTypeAlias_num() { |
| 1273 Source source = addSource(EngineTestCase.createSource(["class M {}", "class
C = num with M;"])); |
| 1274 resolve(source); |
| 1275 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
| 1276 verify([source]); |
| 1277 } |
| 1278 |
| 1279 void test_extendsDisallowedClass_classTypeAlias_String() { |
| 1280 Source source = addSource(EngineTestCase.createSource(["class M {}", "class
C = String with M;"])); |
| 1281 resolve(source); |
| 1282 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
| 1283 verify([source]); |
| 1284 } |
| 1285 |
| 1286 void test_extendsEnum() { |
| 1287 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 1288 analysisOptions.enableEnum = true; |
| 1289 resetWithOptions(analysisOptions); |
| 1290 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "cl
ass A extends E {}"])); |
| 1291 resolve(source); |
| 1292 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); |
| 1293 verify([source]); |
| 1294 } |
| 1295 |
| 1296 void test_extendsNonClass_class() { |
| 1297 Source source = addSource(EngineTestCase.createSource(["int A;", "class B ex
tends A {}"])); |
| 1298 resolve(source); |
| 1299 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); |
| 1300 verify([source]); |
| 1301 } |
| 1302 |
| 1303 void test_extendsNonClass_dynamic() { |
| 1304 Source source = addSource(EngineTestCase.createSource(["class B extends dyna
mic {}"])); |
| 1305 resolve(source); |
| 1306 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); |
| 1307 verify([source]); |
| 1308 } |
| 1309 |
| 1310 void test_extraPositionalArguments_const() { |
| 1311 Source source = addSource(EngineTestCase.createSource([ |
| 1312 "class A {", |
| 1313 " const A();", |
| 1314 "}", |
| 1315 "main() {", |
| 1316 " const A(0);", |
| 1317 "}"])); |
| 1318 resolve(source); |
| 1319 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); |
| 1320 verify([source]); |
| 1321 } |
| 1322 |
| 1323 void test_extraPositionalArguments_const_super() { |
| 1324 Source source = addSource(EngineTestCase.createSource([ |
| 1325 "class A {", |
| 1326 " const A();", |
| 1327 "}", |
| 1328 "class B extends A {", |
| 1329 " const B() : super(0);", |
| 1330 "}"])); |
| 1331 resolve(source); |
| 1332 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); |
| 1333 verify([source]); |
| 1334 } |
| 1335 |
| 1336 void test_fieldInitializedByMultipleInitializers() { |
| 1337 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " A() : x = 0, x = 1 {}", "}"])); |
| 1338 resolve(source); |
| 1339 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INI
TIALIZERS]); |
| 1340 verify([source]); |
| 1341 } |
| 1342 |
| 1343 void test_fieldInitializedByMultipleInitializers_multipleInits() { |
| 1344 Source source = addSource(EngineTestCase.createSource([ |
| 1345 "class A {", |
| 1346 " int x;", |
| 1347 " A() : x = 0, x = 1, x = 2 {}", |
| 1348 "}"])); |
| 1349 resolve(source); |
| 1350 assertErrors(source, [ |
| 1351 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
| 1352 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); |
| 1353 verify([source]); |
| 1354 } |
| 1355 |
| 1356 void test_fieldInitializedByMultipleInitializers_multipleNames() { |
| 1357 Source source = addSource(EngineTestCase.createSource([ |
| 1358 "class A {", |
| 1359 " int x;", |
| 1360 " int y;", |
| 1361 " A() : x = 0, x = 1, y = 0, y = 1 {}", |
| 1362 "}"])); |
| 1363 resolve(source); |
| 1364 assertErrors(source, [ |
| 1365 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
| 1366 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); |
| 1367 verify([source]); |
| 1368 } |
| 1369 |
| 1370 void test_fieldInitializedInParameterAndInitializer() { |
| 1371 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " A(this.x) : x = 1 {}", "}"])); |
| 1372 resolve(source); |
| 1373 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AN
D_INITIALIZER]); |
| 1374 verify([source]); |
| 1375 } |
| 1376 |
| 1377 void test_fieldInitializerFactoryConstructor() { |
| 1378 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " factory A(this.x) {}", "}"])); |
| 1379 resolve(source); |
| 1380 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRU
CTOR]); |
| 1381 verify([source]); |
| 1382 } |
| 1383 |
| 1384 void test_fieldInitializerOutsideConstructor() { |
| 1385 // TODO(brianwilkerson) Fix the duplicate error messages. |
| 1386 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " m(this.x) {}", "}"])); |
| 1387 resolve(source); |
| 1388 assertErrors(source, [ |
| 1389 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, |
| 1390 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); |
| 1391 verify([source]); |
| 1392 } |
| 1393 |
| 1394 void test_fieldInitializerOutsideConstructor_defaultParameter() { |
| 1395 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " m([this.x]) {}", "}"])); |
| 1396 resolve(source); |
| 1397 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRU
CTOR]); |
| 1398 verify([source]); |
| 1399 } |
| 1400 |
| 1401 void test_fieldInitializerRedirectingConstructor_afterRedirection() { |
| 1402 Source source = addSource(EngineTestCase.createSource([ |
| 1403 "class A {", |
| 1404 " int x;", |
| 1405 " A.named() {}", |
| 1406 " A() : this.named(), x = 42;", |
| 1407 "}"])); |
| 1408 resolve(source); |
| 1409 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON
STRUCTOR]); |
| 1410 verify([source]); |
| 1411 } |
| 1412 |
| 1413 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { |
| 1414 Source source = addSource(EngineTestCase.createSource([ |
| 1415 "class A {", |
| 1416 " int x;", |
| 1417 " A.named() {}", |
| 1418 " A() : x = 42, this.named();", |
| 1419 "}"])); |
| 1420 resolve(source); |
| 1421 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON
STRUCTOR]); |
| 1422 verify([source]); |
| 1423 } |
| 1424 |
| 1425 void test_fieldInitializingFormalRedirectingConstructor() { |
| 1426 Source source = addSource(EngineTestCase.createSource([ |
| 1427 "class A {", |
| 1428 " int x;", |
| 1429 " A.named() {}", |
| 1430 " A(this.x) : this.named();", |
| 1431 "}"])); |
| 1432 resolve(source); |
| 1433 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON
STRUCTOR]); |
| 1434 verify([source]); |
| 1435 } |
| 1436 |
| 1437 void test_finalInitializedMultipleTimes_initializers() { |
| 1438 Source source = addSource(EngineTestCase.createSource(["class A {", " final
x;", " A() : x = 0, x = 0 {}", "}"])); |
| 1439 resolve(source); |
| 1440 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INI
TIALIZERS]); |
| 1441 verify([source]); |
| 1442 } |
| 1443 |
| 1444 /** |
| 1445 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests
the |
| 1446 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided
here to show |
| 1447 * coverage over all of the permutations of initializers in constructor declar
ations. |
| 1448 * |
| 1449 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of |
| 1450 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead
of the broader code |
| 1451 */ |
| 1452 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { |
| 1453 Source source = addSource(EngineTestCase.createSource(["class A {", " final
x;", " A(this.x) : x = 0 {}", "}"])); |
| 1454 resolve(source); |
| 1455 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AN
D_INITIALIZER]); |
| 1456 verify([source]); |
| 1457 } |
| 1458 |
| 1459 void test_finalInitializedMultipleTimes_initializingFormals() { |
| 1460 Source source = addSource(EngineTestCase.createSource(["class A {", " final
x;", " A(this.x, this.x) {}", "}"])); |
| 1461 resolve(source); |
| 1462 assertErrors(source, [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES]
); |
| 1463 verify([source]); |
| 1464 } |
| 1465 |
| 1466 void test_finalNotInitialized_instanceField_const_static() { |
| 1467 Source source = addSource(EngineTestCase.createSource(["class A {", " stati
c const F;", "}"])); |
| 1468 resolve(source); |
| 1469 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
| 1470 verify([source]); |
| 1471 } |
| 1472 |
| 1473 void test_finalNotInitialized_library_const() { |
| 1474 Source source = addSource(EngineTestCase.createSource(["const F;"])); |
| 1475 resolve(source); |
| 1476 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
| 1477 verify([source]); |
| 1478 } |
| 1479 |
| 1480 void test_finalNotInitialized_local_const() { |
| 1481 Source source = addSource(EngineTestCase.createSource(["f() {", " const int
x;", "}"])); |
| 1482 resolve(source); |
| 1483 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
| 1484 verify([source]); |
| 1485 } |
| 1486 |
| 1487 void test_fromEnvironment_bool_badArgs() { |
| 1488 Source source = addSource(EngineTestCase.createSource([ |
| 1489 "var b1 = const bool.fromEnvironment(1);", |
| 1490 "var b2 = const bool.fromEnvironment('x', defaultValue: 1);"])); |
| 1491 resolve(source); |
| 1492 assertErrors(source, [ |
| 1493 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 1494 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
| 1495 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 1496 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 1497 verify([source]); |
| 1498 } |
| 1499 |
| 1500 void test_fromEnvironment_bool_badDefault_whenDefined() { |
| 1501 // The type of the defaultValue needs to be correct even when the default va
lue |
| 1502 // isn't used (because the variable is defined in the environment). |
| 1503 analysisContext2.declaredVariables.define("x", "true"); |
| 1504 Source source = addSource(EngineTestCase.createSource(["var b = const bool.f
romEnvironment('x', defaultValue: 1);"])); |
| 1505 resolve(source); |
| 1506 assertErrors(source, [ |
| 1507 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 1508 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 1509 verify([source]); |
| 1510 } |
| 1511 |
| 1512 void test_getterAndMethodWithSameName() { |
| 1513 Source source = addSource(EngineTestCase.createSource(["class A {", " x(y)
{}", " get x => 0;", "}"])); |
| 1514 resolve(source); |
| 1515 assertErrors(source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]
); |
| 1516 verify([source]); |
| 1517 } |
| 1518 |
| 1519 void test_implementsDeferredClass() { |
| 1520 resolveWithAndWithoutExperimental(<String> [ |
| 1521 EngineTestCase.createSource(["library lib1;", "class A {}"]), |
| 1522 EngineTestCase.createSource([ |
| 1523 "library root;", |
| 1524 "import 'lib1.dart' deferred as a;", |
| 1525 "class B implements a.A {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IM
PORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLAS
S]); |
| 1526 } |
| 1527 |
| 1528 void test_implementsDeferredClass_classTypeAlias() { |
| 1529 resolveWithAndWithoutExperimental(<String> [ |
| 1530 EngineTestCase.createSource(["library lib1;", "class A {}"]), |
| 1531 EngineTestCase.createSource([ |
| 1532 "library root;", |
| 1533 "import 'lib1.dart' deferred as a;", |
| 1534 "class B {}", |
| 1535 "class M {}", |
| 1536 "class C = B with M implements a.A;"])], <ErrorCode> [ParserErrorCode.DE
FERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.IMPLEMENTS_DEFE
RRED_CLASS]); |
| 1537 } |
| 1538 |
| 1539 void test_implementsDisallowedClass_class_bool() { |
| 1540 Source source = addSource(EngineTestCase.createSource(["class A implements b
ool {}"])); |
| 1541 resolve(source); |
| 1542 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1543 verify([source]); |
| 1544 } |
| 1545 |
| 1546 void test_implementsDisallowedClass_class_double() { |
| 1547 Source source = addSource(EngineTestCase.createSource(["class A implements d
ouble {}"])); |
| 1548 resolve(source); |
| 1549 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1550 verify([source]); |
| 1551 } |
| 1552 |
| 1553 void test_implementsDisallowedClass_class_int() { |
| 1554 Source source = addSource(EngineTestCase.createSource(["class A implements i
nt {}"])); |
| 1555 resolve(source); |
| 1556 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1557 verify([source]); |
| 1558 } |
| 1559 |
| 1560 void test_implementsDisallowedClass_class_Null() { |
| 1561 Source source = addSource(EngineTestCase.createSource(["class A implements N
ull {}"])); |
| 1562 resolve(source); |
| 1563 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1564 verify([source]); |
| 1565 } |
| 1566 |
| 1567 void test_implementsDisallowedClass_class_num() { |
| 1568 Source source = addSource(EngineTestCase.createSource(["class A implements n
um {}"])); |
| 1569 resolve(source); |
| 1570 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1571 verify([source]); |
| 1572 } |
| 1573 |
| 1574 void test_implementsDisallowedClass_class_String() { |
| 1575 Source source = addSource(EngineTestCase.createSource(["class A implements S
tring {}"])); |
| 1576 resolve(source); |
| 1577 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1578 verify([source]); |
| 1579 } |
| 1580 |
| 1581 void test_implementsDisallowedClass_class_String_num() { |
| 1582 Source source = addSource(EngineTestCase.createSource(["class A implements S
tring, num {}"])); |
| 1583 resolve(source); |
| 1584 assertErrors(source, [ |
| 1585 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, |
| 1586 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1587 verify([source]); |
| 1588 } |
| 1589 |
| 1590 void test_implementsDisallowedClass_classTypeAlias_bool() { |
| 1591 Source source = addSource(EngineTestCase.createSource([ |
| 1592 "class A {}", |
| 1593 "class M {}", |
| 1594 "class C = A with M implements bool;"])); |
| 1595 resolve(source); |
| 1596 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1597 verify([source]); |
| 1598 } |
| 1599 |
| 1600 void test_implementsDisallowedClass_classTypeAlias_double() { |
| 1601 Source source = addSource(EngineTestCase.createSource([ |
| 1602 "class A {}", |
| 1603 "class M {}", |
| 1604 "class C = A with M implements double;"])); |
| 1605 resolve(source); |
| 1606 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1607 verify([source]); |
| 1608 } |
| 1609 |
| 1610 void test_implementsDisallowedClass_classTypeAlias_int() { |
| 1611 Source source = addSource(EngineTestCase.createSource([ |
| 1612 "class A {}", |
| 1613 "class M {}", |
| 1614 "class C = A with M implements int;"])); |
| 1615 resolve(source); |
| 1616 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1617 verify([source]); |
| 1618 } |
| 1619 |
| 1620 void test_implementsDisallowedClass_classTypeAlias_Null() { |
| 1621 Source source = addSource(EngineTestCase.createSource([ |
| 1622 "class A {}", |
| 1623 "class M {}", |
| 1624 "class C = A with M implements Null;"])); |
| 1625 resolve(source); |
| 1626 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1627 verify([source]); |
| 1628 } |
| 1629 |
| 1630 void test_implementsDisallowedClass_classTypeAlias_num() { |
| 1631 Source source = addSource(EngineTestCase.createSource([ |
| 1632 "class A {}", |
| 1633 "class M {}", |
| 1634 "class C = A with M implements num;"])); |
| 1635 resolve(source); |
| 1636 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1637 verify([source]); |
| 1638 } |
| 1639 |
| 1640 void test_implementsDisallowedClass_classTypeAlias_String() { |
| 1641 Source source = addSource(EngineTestCase.createSource([ |
| 1642 "class A {}", |
| 1643 "class M {}", |
| 1644 "class C = A with M implements String;"])); |
| 1645 resolve(source); |
| 1646 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1647 verify([source]); |
| 1648 } |
| 1649 |
| 1650 void test_implementsDisallowedClass_classTypeAlias_String_num() { |
| 1651 Source source = addSource(EngineTestCase.createSource([ |
| 1652 "class A {}", |
| 1653 "class M {}", |
| 1654 "class C = A with M implements String, num;"])); |
| 1655 resolve(source); |
| 1656 assertErrors(source, [ |
| 1657 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, |
| 1658 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 1659 verify([source]); |
| 1660 } |
| 1661 |
| 1662 void test_implementsDynamic() { |
| 1663 Source source = addSource(EngineTestCase.createSource(["class A implements d
ynamic {}"])); |
| 1664 resolve(source); |
| 1665 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); |
| 1666 verify([source]); |
| 1667 } |
| 1668 |
| 1669 void test_implementsEnum() { |
| 1670 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 1671 analysisOptions.enableEnum = true; |
| 1672 resetWithOptions(analysisOptions); |
| 1673 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "cl
ass A implements E {}"])); |
| 1674 resolve(source); |
| 1675 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); |
| 1676 verify([source]); |
| 1677 } |
| 1678 |
| 1679 void test_implementsNonClass_class() { |
| 1680 Source source = addSource(EngineTestCase.createSource(["int A;", "class B im
plements A {}"])); |
| 1681 resolve(source); |
| 1682 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); |
| 1683 verify([source]); |
| 1684 } |
| 1685 |
| 1686 void test_implementsNonClass_typeAlias() { |
| 1687 Source source = addSource(EngineTestCase.createSource([ |
| 1688 "class A {}", |
| 1689 "class M {}", |
| 1690 "int B;", |
| 1691 "class C = A with M implements B;"])); |
| 1692 resolve(source); |
| 1693 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); |
| 1694 verify([source]); |
| 1695 } |
| 1696 |
| 1697 void test_implementsRepeated() { |
| 1698 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
B implements A, A {}"])); |
| 1699 resolve(source); |
| 1700 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]); |
| 1701 verify([source]); |
| 1702 } |
| 1703 |
| 1704 void test_implementsRepeated_3times() { |
| 1705 Source source = addSource(EngineTestCase.createSource([ |
| 1706 "class A {} class C{}", |
| 1707 "class B implements A, A, A, A {}"])); |
| 1708 resolve(source); |
| 1709 assertErrors(source, [ |
| 1710 CompileTimeErrorCode.IMPLEMENTS_REPEATED, |
| 1711 CompileTimeErrorCode.IMPLEMENTS_REPEATED, |
| 1712 CompileTimeErrorCode.IMPLEMENTS_REPEATED]); |
| 1713 verify([source]); |
| 1714 } |
| 1715 |
| 1716 void test_implementsSuperClass() { |
| 1717 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
B extends A implements A {}"])); |
| 1718 resolve(source); |
| 1719 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); |
| 1720 verify([source]); |
| 1721 } |
| 1722 |
| 1723 void test_implementsSuperClass_Object() { |
| 1724 Source source = addSource(EngineTestCase.createSource(["class A implements O
bject {}"])); |
| 1725 resolve(source); |
| 1726 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); |
| 1727 verify([source]); |
| 1728 } |
| 1729 |
| 1730 void test_implicitThisReferenceInInitializer_field() { |
| 1731 Source source = addSource(EngineTestCase.createSource([ |
| 1732 "class A {", |
| 1733 " var v;", |
| 1734 " A() : v = f;", |
| 1735 " var f;", |
| 1736 "}"])); |
| 1737 resolve(source); |
| 1738 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 1739 verify([source]); |
| 1740 } |
| 1741 |
| 1742 void test_implicitThisReferenceInInitializer_field2() { |
| 1743 Source source = addSource(EngineTestCase.createSource(["class A {", " final
x = 0;", " final y = x;", "}"])); |
| 1744 resolve(source); |
| 1745 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 1746 verify([source]); |
| 1747 } |
| 1748 |
| 1749 void test_implicitThisReferenceInInitializer_invocation() { |
| 1750 Source source = addSource(EngineTestCase.createSource([ |
| 1751 "class A {", |
| 1752 " var v;", |
| 1753 " A() : v = f();", |
| 1754 " f() {}", |
| 1755 "}"])); |
| 1756 resolve(source); |
| 1757 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 1758 verify([source]); |
| 1759 } |
| 1760 |
| 1761 void test_implicitThisReferenceInInitializer_invocationInStatic() { |
| 1762 Source source = addSource(EngineTestCase.createSource(["class A {", " stati
c var F = m();", " m() {}", "}"])); |
| 1763 resolve(source); |
| 1764 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 1765 verify([source]); |
| 1766 } |
| 1767 |
| 1768 void test_implicitThisReferenceInInitializer_redirectingConstructorInvocation(
) { |
| 1769 Source source = addSource(EngineTestCase.createSource([ |
| 1770 "class A {", |
| 1771 " A(p) {}", |
| 1772 " A.named() : this(f);", |
| 1773 " var f;", |
| 1774 "}"])); |
| 1775 resolve(source); |
| 1776 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 1777 verify([source]); |
| 1778 } |
| 1779 |
| 1780 void test_implicitThisReferenceInInitializer_superConstructorInvocation() { |
| 1781 Source source = addSource(EngineTestCase.createSource([ |
| 1782 "class A {", |
| 1783 " A(p) {}", |
| 1784 "}", |
| 1785 "class B extends A {", |
| 1786 " B() : super(f);", |
| 1787 " var f;", |
| 1788 "}"])); |
| 1789 resolve(source); |
| 1790 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 1791 verify([source]); |
| 1792 } |
| 1793 |
| 1794 void test_importInternalLibrary() { |
| 1795 Source source = addSource(EngineTestCase.createSource(["import 'dart:_interc
eptors';"])); |
| 1796 resolve(source); |
| 1797 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w
e could prevent |
| 1798 // the hint from being generated by testing the import directive for the err
or, this is such a |
| 1799 // minor corner case that we don't think we should add the additional comput
ation time to figure |
| 1800 // out such cases. |
| 1801 assertErrors(source, [ |
| 1802 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 1803 HintCode.UNUSED_IMPORT]); |
| 1804 verify([source]); |
| 1805 } |
| 1806 |
| 1807 void test_importInternalLibrary_js_helper() { |
| 1808 Source source = addSource(EngineTestCase.createSource(["import 'dart:_js_hel
per';"])); |
| 1809 resolve(source); |
| 1810 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w
e could prevent |
| 1811 // the hint from being generated by testing the import directive for the err
or, this is such a |
| 1812 // minor corner case that we don't think we should add the additional comput
ation time to figure |
| 1813 // out such cases. |
| 1814 assertErrors(source, [ |
| 1815 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 1816 HintCode.UNUSED_IMPORT]); |
| 1817 verify([source]); |
| 1818 } |
| 1819 |
| 1820 void test_importOfNonLibrary() { |
| 1821 Source source = addSource(EngineTestCase.createSource(["library lib;", "impo
rt 'part.dart';", "A a;"])); |
| 1822 addNamedSource("/part.dart", EngineTestCase.createSource(["part of lib;", "c
lass A{}"])); |
| 1823 resolve(source); |
| 1824 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 1825 verify([source]); |
| 1826 } |
| 1827 |
| 1828 void test_inconsistentCaseExpressionTypes() { |
| 1829 Source source = addSource(EngineTestCase.createSource([ |
| 1830 "f(var p) {", |
| 1831 " switch (p) {", |
| 1832 " case 1:", |
| 1833 " break;", |
| 1834 " case 'a':", |
| 1835 " break;", |
| 1836 " }", |
| 1837 "}"])); |
| 1838 resolve(source); |
| 1839 assertErrors(source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPE
S]); |
| 1840 verify([source]); |
| 1841 } |
| 1842 |
| 1843 void test_inconsistentCaseExpressionTypes_dynamic() { |
| 1844 // Even though A.S and S have a static type of "dynamic", we should see |
| 1845 // that they fail to match 3, because they are constant strings. |
| 1846 Source source = addSource(EngineTestCase.createSource([ |
| 1847 "class A {", |
| 1848 " static const S = 'A.S';", |
| 1849 "}", |
| 1850 "", |
| 1851 "const S = 'S';", |
| 1852 "", |
| 1853 "foo(var p) {", |
| 1854 " switch (p) {", |
| 1855 " case 3:", |
| 1856 " break;", |
| 1857 " case S:", |
| 1858 " break;", |
| 1859 " case A.S:", |
| 1860 " break;", |
| 1861 " }", |
| 1862 "}"])); |
| 1863 resolve(source); |
| 1864 assertErrors(source, [ |
| 1865 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
| 1866 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); |
| 1867 verify([source]); |
| 1868 } |
| 1869 |
| 1870 void test_inconsistentCaseExpressionTypes_repeated() { |
| 1871 Source source = addSource(EngineTestCase.createSource([ |
| 1872 "f(var p) {", |
| 1873 " switch (p) {", |
| 1874 " case 1:", |
| 1875 " break;", |
| 1876 " case 'a':", |
| 1877 " break;", |
| 1878 " case 'b':", |
| 1879 " break;", |
| 1880 " }", |
| 1881 "}"])); |
| 1882 resolve(source); |
| 1883 assertErrors(source, [ |
| 1884 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
| 1885 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); |
| 1886 verify([source]); |
| 1887 } |
| 1888 |
| 1889 void test_initializerForNonExistent_const() { |
| 1890 // Check that the absence of a matching field doesn't cause a |
| 1891 // crash during constant evaluation. |
| 1892 Source source = addSource(EngineTestCase.createSource([ |
| 1893 "class A {", |
| 1894 " const A() : x = 'foo';", |
| 1895 "}", |
| 1896 "A a = const A();"])); |
| 1897 resolve(source); |
| 1898 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIEL
D]); |
| 1899 } |
| 1900 |
| 1901 void test_initializerForNonExistent_initializer() { |
| 1902 Source source = addSource(EngineTestCase.createSource(["class A {", " A() :
x = 0 {}", "}"])); |
| 1903 resolve(source); |
| 1904 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIEL
D]); |
| 1905 } |
| 1906 |
| 1907 void test_initializerForStaticField() { |
| 1908 Source source = addSource(EngineTestCase.createSource(["class A {", " stati
c int x;", " A() : x = 0 {}", "}"])); |
| 1909 resolve(source); |
| 1910 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); |
| 1911 verify([source]); |
| 1912 } |
| 1913 |
| 1914 void test_initializingFormalForNonExistentField() { |
| 1915 Source source = addSource(EngineTestCase.createSource(["class A {", " A(thi
s.x) {}", "}"])); |
| 1916 resolve(source); |
| 1917 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST
ENT_FIELD]); |
| 1918 verify([source]); |
| 1919 } |
| 1920 |
| 1921 void test_initializingFormalForNonExistentField_notInEnclosingClass() { |
| 1922 Source source = addSource(EngineTestCase.createSource([ |
| 1923 "class A {", |
| 1924 "int x;", |
| 1925 "}", |
| 1926 "class B extends A {", |
| 1927 " B(this.x) {}", |
| 1928 "}"])); |
| 1929 resolve(source); |
| 1930 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST
ENT_FIELD]); |
| 1931 verify([source]); |
| 1932 } |
| 1933 |
| 1934 void test_initializingFormalForNonExistentField_optional() { |
| 1935 Source source = addSource(EngineTestCase.createSource(["class A {", " A([th
is.x]) {}", "}"])); |
| 1936 resolve(source); |
| 1937 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST
ENT_FIELD]); |
| 1938 verify([source]); |
| 1939 } |
| 1940 |
| 1941 void test_initializingFormalForNonExistentField_synthetic() { |
| 1942 Source source = addSource(EngineTestCase.createSource(["class A {", " int g
et x => 1;", " A(this.x) {}", "}"])); |
| 1943 resolve(source); |
| 1944 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST
ENT_FIELD]); |
| 1945 verify([source]); |
| 1946 } |
| 1947 |
| 1948 void test_initializingFormalForStaticField() { |
| 1949 Source source = addSource(EngineTestCase.createSource(["class A {", " stati
c int x;", " A([this.x]) {}", "}"])); |
| 1950 resolve(source); |
| 1951 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FI
ELD]); |
| 1952 verify([source]); |
| 1953 } |
| 1954 |
| 1955 void test_instanceMemberAccessFromFactory_named() { |
| 1956 Source source = addSource(EngineTestCase.createSource([ |
| 1957 "class A {", |
| 1958 " m() {}", |
| 1959 " A();", |
| 1960 " factory A.make() {", |
| 1961 " m();", |
| 1962 " return new A();", |
| 1963 " }", |
| 1964 "}"])); |
| 1965 resolve(source); |
| 1966 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTO
RY]); |
| 1967 verify([source]); |
| 1968 } |
| 1969 |
| 1970 void test_instanceMemberAccessFromFactory_unnamed() { |
| 1971 Source source = addSource(EngineTestCase.createSource([ |
| 1972 "class A {", |
| 1973 " m() {}", |
| 1974 " A._();", |
| 1975 " factory A() {", |
| 1976 " m();", |
| 1977 " return new A._();", |
| 1978 " }", |
| 1979 "}"])); |
| 1980 resolve(source); |
| 1981 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTO
RY]); |
| 1982 verify([source]); |
| 1983 } |
| 1984 |
| 1985 void test_instanceMemberAccessFromStatic_field() { |
| 1986 Source source = addSource(EngineTestCase.createSource([ |
| 1987 "class A {", |
| 1988 " int f;", |
| 1989 " static foo() {", |
| 1990 " f;", |
| 1991 " }", |
| 1992 "}"])); |
| 1993 resolve(source); |
| 1994 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI
C]); |
| 1995 verify([source]); |
| 1996 } |
| 1997 |
| 1998 void test_instanceMemberAccessFromStatic_getter() { |
| 1999 Source source = addSource(EngineTestCase.createSource([ |
| 2000 "class A {", |
| 2001 " get g => null;", |
| 2002 " static foo() {", |
| 2003 " g;", |
| 2004 " }", |
| 2005 "}"])); |
| 2006 resolve(source); |
| 2007 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI
C]); |
| 2008 verify([source]); |
| 2009 } |
| 2010 |
| 2011 void test_instanceMemberAccessFromStatic_method() { |
| 2012 Source source = addSource(EngineTestCase.createSource([ |
| 2013 "class A {", |
| 2014 " m() {}", |
| 2015 " static foo() {", |
| 2016 " m();", |
| 2017 " }", |
| 2018 "}"])); |
| 2019 resolve(source); |
| 2020 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI
C]); |
| 2021 verify([source]); |
| 2022 } |
| 2023 |
| 2024 void test_instantiateEnum_const() { |
| 2025 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 2026 analysisOptions.enableEnum = true; |
| 2027 resetWithOptions(analysisOptions); |
| 2028 Source source = addSource(EngineTestCase.createSource([ |
| 2029 "enum E { ONE }", |
| 2030 "E e(String name) {", |
| 2031 " return const E();", |
| 2032 "}"])); |
| 2033 resolve(source); |
| 2034 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); |
| 2035 verify([source]); |
| 2036 } |
| 2037 |
| 2038 void test_instantiateEnum_new() { |
| 2039 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 2040 analysisOptions.enableEnum = true; |
| 2041 resetWithOptions(analysisOptions); |
| 2042 Source source = addSource(EngineTestCase.createSource([ |
| 2043 "enum E { ONE }", |
| 2044 "E e(String name) {", |
| 2045 " return new E();", |
| 2046 "}"])); |
| 2047 resolve(source); |
| 2048 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); |
| 2049 verify([source]); |
| 2050 } |
| 2051 |
| 2052 void test_invalidAnnotation_getter() { |
| 2053 Source source = addSource(EngineTestCase.createSource(["get V => 0;", "@V",
"main() {", "}"])); |
| 2054 resolve(source); |
| 2055 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2056 verify([source]); |
| 2057 } |
| 2058 |
| 2059 void test_invalidAnnotation_importWithPrefix_getter() { |
| 2060 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "ge
t V => 0;"])); |
| 2061 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "@p.V", "main() {", "}"])); |
| 2062 resolve(source); |
| 2063 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2064 verify([source]); |
| 2065 } |
| 2066 |
| 2067 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { |
| 2068 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "fi
nal V = 0;"])); |
| 2069 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "@p.V", "main() {", "}"])); |
| 2070 resolve(source); |
| 2071 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2072 verify([source]); |
| 2073 } |
| 2074 |
| 2075 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio
n() { |
| 2076 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "ty
pedef V();"])); |
| 2077 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "@p.V", "main() {", "}"])); |
| 2078 resolve(source); |
| 2079 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2080 verify([source]); |
| 2081 } |
| 2082 |
| 2083 void test_invalidAnnotation_notConstantVariable() { |
| 2084 Source source = addSource(EngineTestCase.createSource(["final V = 0;", "@V",
"main() {", "}"])); |
| 2085 resolve(source); |
| 2086 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2087 verify([source]); |
| 2088 } |
| 2089 |
| 2090 void test_invalidAnnotation_notVariableOrConstructorInvocation() { |
| 2091 Source source = addSource(EngineTestCase.createSource(["typedef V();", "@V",
"main() {", "}"])); |
| 2092 resolve(source); |
| 2093 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2094 verify([source]); |
| 2095 } |
| 2096 |
| 2097 void test_invalidAnnotation_staticMethodReference() { |
| 2098 Source source = addSource(EngineTestCase.createSource([ |
| 2099 "class A {", |
| 2100 " static f() {}", |
| 2101 "}", |
| 2102 "@A.f", |
| 2103 "main() {", |
| 2104 "}"])); |
| 2105 resolve(source); |
| 2106 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2107 verify([source]); |
| 2108 } |
| 2109 |
| 2110 void test_invalidAnnotation_unresolved_identifier() { |
| 2111 Source source = addSource(EngineTestCase.createSource(["@unresolved", "main(
) {", "}"])); |
| 2112 resolve(source); |
| 2113 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2114 } |
| 2115 |
| 2116 void test_invalidAnnotation_unresolved_invocation() { |
| 2117 Source source = addSource(EngineTestCase.createSource(["@Unresolved()", "mai
n() {", "}"])); |
| 2118 resolve(source); |
| 2119 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2120 } |
| 2121 |
| 2122 void test_invalidAnnotation_unresolved_prefixedIdentifier() { |
| 2123 Source source = addSource(EngineTestCase.createSource([ |
| 2124 "import 'dart:math' as p;", |
| 2125 "@p.unresolved", |
| 2126 "main() {", |
| 2127 "}"])); |
| 2128 resolve(source); |
| 2129 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2130 } |
| 2131 |
| 2132 void test_invalidAnnotation_useLibraryScope() { |
| 2133 Source source = addSource(EngineTestCase.createSource(["@foo", "class A {",
" static const foo = null;", "}"])); |
| 2134 resolve(source); |
| 2135 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2136 } |
| 2137 |
| 2138 void test_invalidAnnotationFromDeferredLibrary() { |
| 2139 // See test_invalidAnnotation_notConstantVariable |
| 2140 resolveWithAndWithoutExperimental(<String> [ |
| 2141 EngineTestCase.createSource([ |
| 2142 "library lib1;", |
| 2143 "class V { const V(); }", |
| 2144 "const v = const V();"]), |
| 2145 EngineTestCase.createSource([ |
| 2146 "library root;", |
| 2147 "import 'lib1.dart' deferred as a;", |
| 2148 "@a.v main () {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_
SUPPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_L
IBRARY]); |
| 2149 } |
| 2150 |
| 2151 void test_invalidAnnotationFromDeferredLibrary_constructor() { |
| 2152 // See test_invalidAnnotation_notConstantVariable |
| 2153 resolveWithAndWithoutExperimental(<String> [ |
| 2154 EngineTestCase.createSource(["library lib1;", "class C { const C(); }"])
, |
| 2155 EngineTestCase.createSource([ |
| 2156 "library root;", |
| 2157 "import 'lib1.dart' deferred as a;", |
| 2158 "@a.C() main () {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NO
T_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED
_LIBRARY]); |
| 2159 } |
| 2160 |
| 2161 void test_invalidAnnotationFromDeferredLibrary_namedConstructor() { |
| 2162 // See test_invalidAnnotation_notConstantVariable |
| 2163 resolveWithAndWithoutExperimental(<String> [ |
| 2164 EngineTestCase.createSource(["library lib1;", "class C { const C.name();
}"]), |
| 2165 EngineTestCase.createSource([ |
| 2166 "library root;", |
| 2167 "import 'lib1.dart' deferred as a;", |
| 2168 "@a.C.name() main () {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPOR
TS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEF
ERRED_LIBRARY]); |
| 2169 } |
| 2170 |
| 2171 void test_invalidConstructorName_notEnclosingClassName_defined() { |
| 2172 Source source = addSource(EngineTestCase.createSource(["class A {", " B() :
super();", "}", "class B {}"])); |
| 2173 resolve(source); |
| 2174 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); |
| 2175 // no verify() call, "B" is not resolved |
| 2176 } |
| 2177 |
| 2178 void test_invalidConstructorName_notEnclosingClassName_undefined() { |
| 2179 Source source = addSource(EngineTestCase.createSource(["class A {", " B() :
super();", "}"])); |
| 2180 resolve(source); |
| 2181 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); |
| 2182 // no verify() call, "B" is not resolved |
| 2183 } |
| 2184 |
| 2185 void test_invalidFactoryNameNotAClass_notClassName() { |
| 2186 Source source = addSource(EngineTestCase.createSource(["int B;", "class A {"
, " factory B() {}", "}"])); |
| 2187 resolve(source); |
| 2188 assertErrors(source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]
); |
| 2189 verify([source]); |
| 2190 } |
| 2191 |
| 2192 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { |
| 2193 Source source = addSource(EngineTestCase.createSource(["class A {", " facto
ry B() {}", "}"])); |
| 2194 resolve(source); |
| 2195 assertErrors(source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]
); |
| 2196 // no verify() call, "B" is not resolved |
| 2197 } |
| 2198 |
| 2199 void test_invalidModifierOnConstructor_async() { |
| 2200 resetWithAsync(); |
| 2201 Source source = addSource(EngineTestCase.createSource(["class A {", " A() a
sync {}", "}"])); |
| 2202 resolve(source); |
| 2203 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR])
; |
| 2204 verify([source]); |
| 2205 } |
| 2206 |
| 2207 void test_invalidModifierOnConstructor_asyncStar() { |
| 2208 resetWithAsync(); |
| 2209 Source source = addSource(EngineTestCase.createSource(["class A {", " A() a
sync* {}", "}"])); |
| 2210 resolve(source); |
| 2211 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR])
; |
| 2212 verify([source]); |
| 2213 } |
| 2214 |
| 2215 void test_invalidModifierOnConstructor_syncStar() { |
| 2216 resetWithAsync(); |
| 2217 Source source = addSource(EngineTestCase.createSource(["class A {", " A() s
ync* {}", "}"])); |
| 2218 resolve(source); |
| 2219 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR])
; |
| 2220 verify([source]); |
| 2221 } |
| 2222 |
| 2223 void test_invalidModifierOnSetter_member_async() { |
| 2224 resetWithAsync(); |
| 2225 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
(v) async {}", "}"])); |
| 2226 resolve(source); |
| 2227 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
| 2228 verify([source]); |
| 2229 } |
| 2230 |
| 2231 void test_invalidModifierOnSetter_member_asyncStar() { |
| 2232 resetWithAsync(); |
| 2233 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
(v) async* {}", "}"])); |
| 2234 resolve(source); |
| 2235 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
| 2236 verify([source]); |
| 2237 } |
| 2238 |
| 2239 void test_invalidModifierOnSetter_member_syncStar() { |
| 2240 resetWithAsync(); |
| 2241 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
(v) sync* {}", "}"])); |
| 2242 resolve(source); |
| 2243 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
| 2244 verify([source]); |
| 2245 } |
| 2246 |
| 2247 void test_invalidModifierOnSetter_topLevel_async() { |
| 2248 resetWithAsync(); |
| 2249 Source source = addSource(EngineTestCase.createSource(["set x(v) async {}"])
); |
| 2250 resolve(source); |
| 2251 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
| 2252 verify([source]); |
| 2253 } |
| 2254 |
| 2255 void test_invalidModifierOnSetter_topLevel_asyncStar() { |
| 2256 resetWithAsync(); |
| 2257 Source source = addSource(EngineTestCase.createSource(["set x(v) async* {}"]
)); |
| 2258 resolve(source); |
| 2259 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
| 2260 verify([source]); |
| 2261 } |
| 2262 |
| 2263 void test_invalidModifierOnSetter_topLevel_syncStar() { |
| 2264 resetWithAsync(); |
| 2265 Source source = addSource(EngineTestCase.createSource(["set x(v) sync* {}"])
); |
| 2266 resolve(source); |
| 2267 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
| 2268 verify([source]); |
| 2269 } |
| 2270 |
| 2271 void test_invalidReferenceToThis_factoryConstructor() { |
| 2272 Source source = addSource(EngineTestCase.createSource(["class A {", " facto
ry A() { return this; }", "}"])); |
| 2273 resolve(source); |
| 2274 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2275 verify([source]); |
| 2276 } |
| 2277 |
| 2278 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() { |
| 2279 Source source = addSource(EngineTestCase.createSource(["class A {", " var f
;", " A() : f = this;", "}"])); |
| 2280 resolve(source); |
| 2281 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2282 verify([source]); |
| 2283 } |
| 2284 |
| 2285 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() { |
| 2286 Source source = addSource(EngineTestCase.createSource(["class A {", " var f
= this;", "}"])); |
| 2287 resolve(source); |
| 2288 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2289 verify([source]); |
| 2290 } |
| 2291 |
| 2292 void test_invalidReferenceToThis_staticMethod() { |
| 2293 Source source = addSource(EngineTestCase.createSource(["class A {", " stati
c m() { return this; }", "}"])); |
| 2294 resolve(source); |
| 2295 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2296 verify([source]); |
| 2297 } |
| 2298 |
| 2299 void test_invalidReferenceToThis_staticVariableInitializer() { |
| 2300 Source source = addSource(EngineTestCase.createSource(["class A {", " stati
c A f = this;", "}"])); |
| 2301 resolve(source); |
| 2302 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2303 verify([source]); |
| 2304 } |
| 2305 |
| 2306 void test_invalidReferenceToThis_superInitializer() { |
| 2307 Source source = addSource(EngineTestCase.createSource([ |
| 2308 "class A {", |
| 2309 " A(var x) {}", |
| 2310 "}", |
| 2311 "class B extends A {", |
| 2312 " B() : super(this);", |
| 2313 "}"])); |
| 2314 resolve(source); |
| 2315 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2316 verify([source]); |
| 2317 } |
| 2318 |
| 2319 void test_invalidReferenceToThis_topLevelFunction() { |
| 2320 Source source = addSource("f() { return this; }"); |
| 2321 resolve(source); |
| 2322 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2323 verify([source]); |
| 2324 } |
| 2325 |
| 2326 void test_invalidReferenceToThis_variableInitializer() { |
| 2327 Source source = addSource("int x = this;"); |
| 2328 resolve(source); |
| 2329 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
| 2330 verify([source]); |
| 2331 } |
| 2332 |
| 2333 void test_invalidTypeArgumentInConstList() { |
| 2334 Source source = addSource(EngineTestCase.createSource([ |
| 2335 "class A<E> {", |
| 2336 " m() {", |
| 2337 " return const <E>[];", |
| 2338 " }", |
| 2339 "}"])); |
| 2340 resolve(source); |
| 2341 assertErrors(source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LI
ST]); |
| 2342 verify([source]); |
| 2343 } |
| 2344 |
| 2345 void test_invalidTypeArgumentInConstMap() { |
| 2346 Source source = addSource(EngineTestCase.createSource([ |
| 2347 "class A<E> {", |
| 2348 " m() {", |
| 2349 " return const <String, E>{};", |
| 2350 " }", |
| 2351 "}"])); |
| 2352 resolve(source); |
| 2353 assertErrors(source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MA
P]); |
| 2354 verify([source]); |
| 2355 } |
| 2356 |
| 2357 void test_invalidUri_export() { |
| 2358 Source source = addSource(EngineTestCase.createSource(["export 'ht:';"])); |
| 2359 resolve(source); |
| 2360 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); |
| 2361 } |
| 2362 |
| 2363 void test_invalidUri_import() { |
| 2364 Source source = addSource(EngineTestCase.createSource(["import 'ht:';"])); |
| 2365 resolve(source); |
| 2366 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); |
| 2367 } |
| 2368 |
| 2369 void test_invalidUri_part() { |
| 2370 Source source = addSource(EngineTestCase.createSource(["part 'ht:';"])); |
| 2371 resolve(source); |
| 2372 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); |
| 2373 } |
| 2374 |
| 2375 void test_labelInOuterScope() { |
| 2376 Source source = addSource(EngineTestCase.createSource([ |
| 2377 "class A {", |
| 2378 " void m(int i) {", |
| 2379 " l: while (i > 0) {", |
| 2380 " void f() {", |
| 2381 " break l;", |
| 2382 " };", |
| 2383 " }", |
| 2384 " }", |
| 2385 "}"])); |
| 2386 resolve(source); |
| 2387 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]); |
| 2388 // We cannot verify resolution with unresolvable labels |
| 2389 } |
| 2390 |
| 2391 void test_labelUndefined_break() { |
| 2392 Source source = addSource(EngineTestCase.createSource([ |
| 2393 "f() {", |
| 2394 " x: while (true) {", |
| 2395 " break y;", |
| 2396 " }", |
| 2397 "}"])); |
| 2398 resolve(source); |
| 2399 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); |
| 2400 // We cannot verify resolution with undefined labels |
| 2401 } |
| 2402 |
| 2403 void test_labelUndefined_continue() { |
| 2404 Source source = addSource(EngineTestCase.createSource([ |
| 2405 "f() {", |
| 2406 " x: while (true) {", |
| 2407 " continue y;", |
| 2408 " }", |
| 2409 "}"])); |
| 2410 resolve(source); |
| 2411 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); |
| 2412 // We cannot verify resolution with undefined labels |
| 2413 } |
| 2414 |
| 2415 void test_memberWithClassName_field() { |
| 2416 Source source = addSource(EngineTestCase.createSource(["class A {", " int A
= 0;", "}"])); |
| 2417 resolve(source); |
| 2418 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); |
| 2419 verify([source]); |
| 2420 } |
| 2421 |
| 2422 void test_memberWithClassName_field2() { |
| 2423 Source source = addSource(EngineTestCase.createSource(["class A {", " int z
, A, b = 0;", "}"])); |
| 2424 resolve(source); |
| 2425 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); |
| 2426 verify([source]); |
| 2427 } |
| 2428 |
| 2429 void test_memberWithClassName_getter() { |
| 2430 Source source = addSource(EngineTestCase.createSource(["class A {", " get A
=> 0;", "}"])); |
| 2431 resolve(source); |
| 2432 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); |
| 2433 verify([source]); |
| 2434 } |
| 2435 |
| 2436 void test_memberWithClassName_method() { |
| 2437 // no test because indistinguishable from constructor |
| 2438 } |
| 2439 |
| 2440 void test_methodAndGetterWithSameName() { |
| 2441 Source source = addSource(EngineTestCase.createSource(["class A {", " get x
=> 0;", " x(y) {}", "}"])); |
| 2442 resolve(source); |
| 2443 assertErrors(source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]
); |
| 2444 verify([source]); |
| 2445 } |
| 2446 |
| 2447 void test_missingEnumConstantInSwitch() { |
| 2448 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 2449 analysisOptions.enableEnum = true; |
| 2450 resetWithOptions(analysisOptions); |
| 2451 Source source = addSource(EngineTestCase.createSource([ |
| 2452 "enum E { ONE, TWO, THREE, FOUR }", |
| 2453 "bool odd(E e) {", |
| 2454 " switch (e) {", |
| 2455 " case E.ONE:", |
| 2456 " case E.THREE: return true;", |
| 2457 " }", |
| 2458 " return false;", |
| 2459 "}"])); |
| 2460 resolve(source); |
| 2461 assertErrors(source, [ |
| 2462 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, |
| 2463 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH]); |
| 2464 verify([source]); |
| 2465 } |
| 2466 |
| 2467 void test_mixinDeclaresConstructor_classDeclaration() { |
| 2468 Source source = addSource(EngineTestCase.createSource([ |
| 2469 "class A {", |
| 2470 " A() {}", |
| 2471 "}", |
| 2472 "class B extends Object with A {}"])); |
| 2473 resolve(source); |
| 2474 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
| 2475 verify([source]); |
| 2476 } |
| 2477 |
| 2478 void test_mixinDeclaresConstructor_typeAlias() { |
| 2479 Source source = addSource(EngineTestCase.createSource(["class A {", " A() {
}", "}", "class B = Object with A;"])); |
| 2480 resolve(source); |
| 2481 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
| 2482 verify([source]); |
| 2483 } |
| 2484 |
| 2485 void test_mixinDeferredClass() { |
| 2486 resolveWithAndWithoutExperimental(<String> [ |
| 2487 EngineTestCase.createSource(["library lib1;", "class A {}"]), |
| 2488 EngineTestCase.createSource([ |
| 2489 "library root;", |
| 2490 "import 'lib1.dart' deferred as a;", |
| 2491 "class B extends Object with a.A {}"])], <ErrorCode> [ParserErrorCode.DE
FERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_
CLASS]); |
| 2492 } |
| 2493 |
| 2494 void test_mixinDeferredClass_classTypeAlias() { |
| 2495 resolveWithAndWithoutExperimental(<String> [ |
| 2496 EngineTestCase.createSource(["library lib1;", "class A {}"]), |
| 2497 EngineTestCase.createSource([ |
| 2498 "library root;", |
| 2499 "import 'lib1.dart' deferred as a;", |
| 2500 "class B {}", |
| 2501 "class C = B with a.A;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORT
S_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]); |
| 2502 } |
| 2503 |
| 2504 void test_mixinInheritsFromNotObject_classDeclaration_extends() { |
| 2505 Source source = addSource(EngineTestCase.createSource([ |
| 2506 "class A {}", |
| 2507 "class B extends A {}", |
| 2508 "class C extends Object with B {}"])); |
| 2509 resolve(source); |
| 2510 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
| 2511 verify([source]); |
| 2512 } |
| 2513 |
| 2514 void test_mixinInheritsFromNotObject_classDeclaration_with() { |
| 2515 Source source = addSource(EngineTestCase.createSource([ |
| 2516 "class A {}", |
| 2517 "class B extends Object with A {}", |
| 2518 "class C extends Object with B {}"])); |
| 2519 resolve(source); |
| 2520 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
| 2521 verify([source]); |
| 2522 } |
| 2523 |
| 2524 void test_mixinInheritsFromNotObject_typeAlias_extends() { |
| 2525 Source source = addSource(EngineTestCase.createSource([ |
| 2526 "class A {}", |
| 2527 "class B extends A {}", |
| 2528 "class C = Object with B;"])); |
| 2529 resolve(source); |
| 2530 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
| 2531 verify([source]); |
| 2532 } |
| 2533 |
| 2534 void test_mixinInheritsFromNotObject_typeAlias_with() { |
| 2535 Source source = addSource(EngineTestCase.createSource([ |
| 2536 "class A {}", |
| 2537 "class B extends Object with A {}", |
| 2538 "class C = Object with B;"])); |
| 2539 resolve(source); |
| 2540 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
| 2541 verify([source]); |
| 2542 } |
| 2543 |
| 2544 void test_mixinOfDisallowedClass_class_bool() { |
| 2545 Source source = addSource(EngineTestCase.createSource(["class A extends Obje
ct with bool {}"])); |
| 2546 resolve(source); |
| 2547 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2548 verify([source]); |
| 2549 } |
| 2550 |
| 2551 void test_mixinOfDisallowedClass_class_double() { |
| 2552 Source source = addSource(EngineTestCase.createSource(["class A extends Obje
ct with double {}"])); |
| 2553 resolve(source); |
| 2554 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2555 verify([source]); |
| 2556 } |
| 2557 |
| 2558 void test_mixinOfDisallowedClass_class_int() { |
| 2559 Source source = addSource(EngineTestCase.createSource(["class A extends Obje
ct with int {}"])); |
| 2560 resolve(source); |
| 2561 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2562 verify([source]); |
| 2563 } |
| 2564 |
| 2565 void test_mixinOfDisallowedClass_class_Null() { |
| 2566 Source source = addSource(EngineTestCase.createSource(["class A extends Obje
ct with Null {}"])); |
| 2567 resolve(source); |
| 2568 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2569 verify([source]); |
| 2570 } |
| 2571 |
| 2572 void test_mixinOfDisallowedClass_class_num() { |
| 2573 Source source = addSource(EngineTestCase.createSource(["class A extends Obje
ct with num {}"])); |
| 2574 resolve(source); |
| 2575 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2576 verify([source]); |
| 2577 } |
| 2578 |
| 2579 void test_mixinOfDisallowedClass_class_String() { |
| 2580 Source source = addSource(EngineTestCase.createSource(["class A extends Obje
ct with String {}"])); |
| 2581 resolve(source); |
| 2582 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2583 verify([source]); |
| 2584 } |
| 2585 |
| 2586 void test_mixinOfDisallowedClass_classTypeAlias_bool() { |
| 2587 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with bool;"])); |
| 2588 resolve(source); |
| 2589 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2590 verify([source]); |
| 2591 } |
| 2592 |
| 2593 void test_mixinOfDisallowedClass_classTypeAlias_double() { |
| 2594 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with double;"])); |
| 2595 resolve(source); |
| 2596 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2597 verify([source]); |
| 2598 } |
| 2599 |
| 2600 void test_mixinOfDisallowedClass_classTypeAlias_int() { |
| 2601 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with int;"])); |
| 2602 resolve(source); |
| 2603 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2604 verify([source]); |
| 2605 } |
| 2606 |
| 2607 void test_mixinOfDisallowedClass_classTypeAlias_Null() { |
| 2608 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with Null;"])); |
| 2609 resolve(source); |
| 2610 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2611 verify([source]); |
| 2612 } |
| 2613 |
| 2614 void test_mixinOfDisallowedClass_classTypeAlias_num() { |
| 2615 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with num;"])); |
| 2616 resolve(source); |
| 2617 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2618 verify([source]); |
| 2619 } |
| 2620 |
| 2621 void test_mixinOfDisallowedClass_classTypeAlias_String() { |
| 2622 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with String;"])); |
| 2623 resolve(source); |
| 2624 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2625 verify([source]); |
| 2626 } |
| 2627 |
| 2628 void test_mixinOfDisallowedClass_classTypeAlias_String_num() { |
| 2629 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
C = A with String, num;"])); |
| 2630 resolve(source); |
| 2631 assertErrors(source, [ |
| 2632 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, |
| 2633 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 2634 verify([source]); |
| 2635 } |
| 2636 |
| 2637 void test_mixinOfEnum() { |
| 2638 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 2639 analysisOptions.enableEnum = true; |
| 2640 resetWithOptions(analysisOptions); |
| 2641 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "cl
ass A extends Object with E {}"])); |
| 2642 resolve(source); |
| 2643 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); |
| 2644 verify([source]); |
| 2645 } |
| 2646 |
| 2647 void test_mixinOfNonClass_class() { |
| 2648 Source source = addSource(EngineTestCase.createSource(["int A;", "class B ex
tends Object with A {}"])); |
| 2649 resolve(source); |
| 2650 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
| 2651 verify([source]); |
| 2652 } |
| 2653 |
| 2654 void test_mixinOfNonClass_typeAlias() { |
| 2655 Source source = addSource(EngineTestCase.createSource(["class A {}", "int B;
", "class C = A with B;"])); |
| 2656 resolve(source); |
| 2657 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
| 2658 verify([source]); |
| 2659 } |
| 2660 |
| 2661 void test_mixinReferencesSuper() { |
| 2662 Source source = addSource(EngineTestCase.createSource([ |
| 2663 "class A {", |
| 2664 " toString() => super.toString();", |
| 2665 "}", |
| 2666 "class B extends Object with A {}"])); |
| 2667 resolve(source); |
| 2668 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); |
| 2669 verify([source]); |
| 2670 } |
| 2671 |
| 2672 void test_mixinWithNonClassSuperclass_class() { |
| 2673 Source source = addSource(EngineTestCase.createSource(["int A;", "class B {}
", "class C extends A with B {}"])); |
| 2674 resolve(source); |
| 2675 assertErrors(source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS])
; |
| 2676 verify([source]); |
| 2677 } |
| 2678 |
| 2679 void test_mixinWithNonClassSuperclass_typeAlias() { |
| 2680 Source source = addSource(EngineTestCase.createSource(["int A;", "class B {}
", "class C = A with B;"])); |
| 2681 resolve(source); |
| 2682 assertErrors(source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS])
; |
| 2683 verify([source]); |
| 2684 } |
| 2685 |
| 2686 void test_multipleRedirectingConstructorInvocations() { |
| 2687 Source source = addSource(EngineTestCase.createSource([ |
| 2688 "class A {", |
| 2689 " A() : this.a(), this.b();", |
| 2690 " A.a() {}", |
| 2691 " A.b() {}", |
| 2692 "}"])); |
| 2693 resolve(source); |
| 2694 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_
INVOCATIONS]); |
| 2695 verify([source]); |
| 2696 } |
| 2697 |
| 2698 void test_multipleSuperInitializers() { |
| 2699 Source source = addSource(EngineTestCase.createSource([ |
| 2700 "class A {}", |
| 2701 "class B extends A {", |
| 2702 " B() : super(), super() {}", |
| 2703 "}"])); |
| 2704 resolve(source); |
| 2705 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); |
| 2706 verify([source]); |
| 2707 } |
| 2708 |
| 2709 void test_nativeClauseInNonSDKCode() { |
| 2710 // TODO(jwren) Move this test somewhere else: This test verifies a parser er
ror code is generated |
| 2711 // through the ErrorVerifier, it is not a CompileTimeErrorCode. |
| 2712 Source source = addSource(EngineTestCase.createSource(["class A native 'stri
ng' {}"])); |
| 2713 resolve(source); |
| 2714 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); |
| 2715 verify([source]); |
| 2716 } |
| 2717 |
| 2718 void test_nativeFunctionBodyInNonSDKCode_function() { |
| 2719 // TODO(jwren) Move this test somewhere else: This test verifies a parser er
ror code is generated |
| 2720 // through the ErrorVerifier, it is not a CompileTimeErrorCode. |
| 2721 Source source = addSource(EngineTestCase.createSource(["int m(a) native 'str
ing';"])); |
| 2722 resolve(source); |
| 2723 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE])
; |
| 2724 verify([source]); |
| 2725 } |
| 2726 |
| 2727 void test_nativeFunctionBodyInNonSDKCode_method() { |
| 2728 // TODO(jwren) Move this test somewhere else: This test verifies a parser er
ror code is generated |
| 2729 // through the ErrorVerifier, it is not a CompileTimeErrorCode. |
| 2730 Source source = addSource(EngineTestCase.createSource(["class A{", " static
int m(a) native 'string';", "}"])); |
| 2731 resolve(source); |
| 2732 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE])
; |
| 2733 verify([source]); |
| 2734 } |
| 2735 |
| 2736 void test_noAnnotationConstructorArguments() { |
| 2737 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "@A", "main() {", "}"])); |
| 2738 resolve(source); |
| 2739 assertErrors(source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMEN
TS]); |
| 2740 verify([source]); |
| 2741 } |
| 2742 |
| 2743 void test_noDefaultSuperConstructorExplicit() { |
| 2744 Source source = addSource(EngineTestCase.createSource([ |
| 2745 "class A {", |
| 2746 " A(p);", |
| 2747 "}", |
| 2748 "class B extends A {", |
| 2749 " B() {}", |
| 2750 "}"])); |
| 2751 resolve(source); |
| 2752 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPL
ICIT]); |
| 2753 verify([source]); |
| 2754 } |
| 2755 |
| 2756 void test_noDefaultSuperConstructorImplicit_superHasParameters() { |
| 2757 Source source = addSource(EngineTestCase.createSource(["class A {", " A(p);
", "}", "class B extends A {", "}"])); |
| 2758 resolve(source); |
| 2759 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL
ICIT]); |
| 2760 verify([source]); |
| 2761 } |
| 2762 |
| 2763 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() { |
| 2764 Source source = addSource(EngineTestCase.createSource(["class A { A.named()
{} }", "class B extends A {}"])); |
| 2765 resolve(source); |
| 2766 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL
ICIT]); |
| 2767 verify([source]); |
| 2768 } |
| 2769 |
| 2770 void test_nonConstantAnnotationConstructor_named() { |
| 2771 Source source = addSource(EngineTestCase.createSource([ |
| 2772 "class A {", |
| 2773 " A.fromInt() {}", |
| 2774 "}", |
| 2775 "@A.fromInt()", |
| 2776 "main() {", |
| 2777 "}"])); |
| 2778 resolve(source); |
| 2779 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCT
OR]); |
| 2780 verify([source]); |
| 2781 } |
| 2782 |
| 2783 void test_nonConstantAnnotationConstructor_unnamed() { |
| 2784 Source source = addSource(EngineTestCase.createSource(["class A {", " A() {
}", "}", "@A()", "main() {", "}"])); |
| 2785 resolve(source); |
| 2786 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCT
OR]); |
| 2787 verify([source]); |
| 2788 } |
| 2789 |
| 2790 void test_nonConstantDefaultValue_function_named() { |
| 2791 Source source = addSource(EngineTestCase.createSource(["int y;", "f({x : y})
{}"])); |
| 2792 resolve(source); |
| 2793 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
| 2794 verify([source]); |
| 2795 } |
| 2796 |
| 2797 void test_nonConstantDefaultValue_function_positional() { |
| 2798 Source source = addSource(EngineTestCase.createSource(["int y;", "f([x = y])
{}"])); |
| 2799 resolve(source); |
| 2800 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
| 2801 verify([source]); |
| 2802 } |
| 2803 |
| 2804 void test_nonConstantDefaultValue_inConstructor_named() { |
| 2805 Source source = addSource(EngineTestCase.createSource(["class A {", " int y
;", " A({x : y}) {}", "}"])); |
| 2806 resolve(source); |
| 2807 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
| 2808 verify([source]); |
| 2809 } |
| 2810 |
| 2811 void test_nonConstantDefaultValue_inConstructor_positional() { |
| 2812 Source source = addSource(EngineTestCase.createSource(["class A {", " int y
;", " A([x = y]) {}", "}"])); |
| 2813 resolve(source); |
| 2814 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
| 2815 verify([source]); |
| 2816 } |
| 2817 |
| 2818 void test_nonConstantDefaultValue_method_named() { |
| 2819 Source source = addSource(EngineTestCase.createSource(["class A {", " int y
;", " m({x : y}) {}", "}"])); |
| 2820 resolve(source); |
| 2821 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
| 2822 verify([source]); |
| 2823 } |
| 2824 |
| 2825 void test_nonConstantDefaultValue_method_positional() { |
| 2826 Source source = addSource(EngineTestCase.createSource(["class A {", " int y
;", " m([x = y]) {}", "}"])); |
| 2827 resolve(source); |
| 2828 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
| 2829 verify([source]); |
| 2830 } |
| 2831 |
| 2832 void test_nonConstantDefaultValueFromDeferredLibrary() { |
| 2833 resolveWithAndWithoutExperimental(<String> [ |
| 2834 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), |
| 2835 EngineTestCase.createSource([ |
| 2836 "library root;", |
| 2837 "import 'lib1.dart' deferred as a;", |
| 2838 "f({x : a.V}) {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_
SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DE
FERRED_LIBRARY]); |
| 2839 } |
| 2840 |
| 2841 void test_nonConstantDefaultValueFromDeferredLibrary_nested() { |
| 2842 resolveWithAndWithoutExperimental(<String> [ |
| 2843 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), |
| 2844 EngineTestCase.createSource([ |
| 2845 "library root;", |
| 2846 "import 'lib1.dart' deferred as a;", |
| 2847 "f({x : a.V + 1}) {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_
NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FRO
M_DEFERRED_LIBRARY]); |
| 2848 } |
| 2849 |
| 2850 void test_nonConstCaseExpression() { |
| 2851 Source source = addSource(EngineTestCase.createSource([ |
| 2852 "f(int p, int q) {", |
| 2853 " switch (p) {", |
| 2854 " case 3 + q:", |
| 2855 " break;", |
| 2856 " }", |
| 2857 "}"])); |
| 2858 resolve(source); |
| 2859 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]); |
| 2860 verify([source]); |
| 2861 } |
| 2862 |
| 2863 void test_nonConstCaseExpressionFromDeferredLibrary() { |
| 2864 resolveWithAndWithoutExperimental(<String> [ |
| 2865 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2866 EngineTestCase.createSource([ |
| 2867 "library root;", |
| 2868 "import 'lib1.dart' deferred as a;", |
| 2869 "main (int p) {", |
| 2870 " switch (p) {", |
| 2871 " case a.c:", |
| 2872 " break;", |
| 2873 " }", |
| 2874 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRA
RY]); |
| 2875 } |
| 2876 |
| 2877 void test_nonConstCaseExpressionFromDeferredLibrary_nested() { |
| 2878 resolveWithAndWithoutExperimental(<String> [ |
| 2879 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2880 EngineTestCase.createSource([ |
| 2881 "library root;", |
| 2882 "import 'lib1.dart' deferred as a;", |
| 2883 "main (int p) {", |
| 2884 " switch (p) {", |
| 2885 " case a.c + 1:", |
| 2886 " break;", |
| 2887 " }", |
| 2888 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRA
RY]); |
| 2889 } |
| 2890 |
| 2891 void test_nonConstListElement() { |
| 2892 Source source = addSource(EngineTestCase.createSource(["f(a) {", " return c
onst [a];", "}"])); |
| 2893 resolve(source); |
| 2894 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]); |
| 2895 verify([source]); |
| 2896 } |
| 2897 |
| 2898 void test_nonConstListElementFromDeferredLibrary() { |
| 2899 resolveWithAndWithoutExperimental(<String> [ |
| 2900 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2901 EngineTestCase.createSource([ |
| 2902 "library root;", |
| 2903 "import 'lib1.dart' deferred as a;", |
| 2904 "f() {", |
| 2905 " return const [a.c];", |
| 2906 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]
); |
| 2907 } |
| 2908 |
| 2909 void test_nonConstListElementFromDeferredLibrary_nested() { |
| 2910 resolveWithAndWithoutExperimental(<String> [ |
| 2911 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2912 EngineTestCase.createSource([ |
| 2913 "library root;", |
| 2914 "import 'lib1.dart' deferred as a;", |
| 2915 "f() {", |
| 2916 " return const [a.c + 1];", |
| 2917 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]
); |
| 2918 } |
| 2919 |
| 2920 void test_nonConstMapAsExpressionStatement_begin() { |
| 2921 Source source = addSource(EngineTestCase.createSource(["f() {", " {'a' : 0,
'b' : 1}.length;", "}"])); |
| 2922 resolve(source); |
| 2923 assertErrors(source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATE
MENT]); |
| 2924 verify([source]); |
| 2925 } |
| 2926 |
| 2927 void test_nonConstMapAsExpressionStatement_only() { |
| 2928 Source source = addSource(EngineTestCase.createSource(["f() {", " {'a' : 0,
'b' : 1};", "}"])); |
| 2929 resolve(source); |
| 2930 assertErrors(source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATE
MENT]); |
| 2931 verify([source]); |
| 2932 } |
| 2933 |
| 2934 void test_nonConstMapKey() { |
| 2935 Source source = addSource(EngineTestCase.createSource(["f(a) {", " return c
onst {a : 0};", "}"])); |
| 2936 resolve(source); |
| 2937 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]); |
| 2938 verify([source]); |
| 2939 } |
| 2940 |
| 2941 void test_nonConstMapKeyFromDeferredLibrary() { |
| 2942 resolveWithAndWithoutExperimental(<String> [ |
| 2943 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2944 EngineTestCase.createSource([ |
| 2945 "library root;", |
| 2946 "import 'lib1.dart' deferred as a;", |
| 2947 "f() {", |
| 2948 " return const {a.c : 0};", |
| 2949 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]); |
| 2950 } |
| 2951 |
| 2952 void test_nonConstMapKeyFromDeferredLibrary_nested() { |
| 2953 resolveWithAndWithoutExperimental(<String> [ |
| 2954 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2955 EngineTestCase.createSource([ |
| 2956 "library root;", |
| 2957 "import 'lib1.dart' deferred as a;", |
| 2958 "f() {", |
| 2959 " return const {a.c + 1 : 0};", |
| 2960 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]); |
| 2961 } |
| 2962 |
| 2963 void test_nonConstMapValue() { |
| 2964 Source source = addSource(EngineTestCase.createSource(["f(a) {", " return c
onst {'a' : a};", "}"])); |
| 2965 resolve(source); |
| 2966 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]); |
| 2967 verify([source]); |
| 2968 } |
| 2969 |
| 2970 void test_nonConstMapValueFromDeferredLibrary() { |
| 2971 resolveWithAndWithoutExperimental(<String> [ |
| 2972 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2973 EngineTestCase.createSource([ |
| 2974 "library root;", |
| 2975 "import 'lib1.dart' deferred as a;", |
| 2976 "f() {", |
| 2977 " return const {'a' : a.c};", |
| 2978 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]); |
| 2979 } |
| 2980 |
| 2981 void test_nonConstMapValueFromDeferredLibrary_nested() { |
| 2982 resolveWithAndWithoutExperimental(<String> [ |
| 2983 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 2984 EngineTestCase.createSource([ |
| 2985 "library root;", |
| 2986 "import 'lib1.dart' deferred as a;", |
| 2987 "f() {", |
| 2988 " return const {'a' : a.c + 1};", |
| 2989 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]); |
| 2990 } |
| 2991 |
| 2992 void test_nonConstValueInInitializer_binary_notBool_left() { |
| 2993 Source source = addSource(EngineTestCase.createSource([ |
| 2994 "class A {", |
| 2995 " final bool a;", |
| 2996 " const A(String p) : a = p && true;", |
| 2997 "}"])); |
| 2998 resolve(source); |
| 2999 assertErrors(source, [ |
| 3000 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
| 3001 StaticTypeWarningCode.NON_BOOL_OPERAND]); |
| 3002 verify([source]); |
| 3003 } |
| 3004 |
| 3005 void test_nonConstValueInInitializer_binary_notBool_right() { |
| 3006 Source source = addSource(EngineTestCase.createSource([ |
| 3007 "class A {", |
| 3008 " final bool a;", |
| 3009 " const A(String p) : a = true && p;", |
| 3010 "}"])); |
| 3011 resolve(source); |
| 3012 assertErrors(source, [ |
| 3013 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
| 3014 StaticTypeWarningCode.NON_BOOL_OPERAND]); |
| 3015 verify([source]); |
| 3016 } |
| 3017 |
| 3018 void test_nonConstValueInInitializer_binary_notInt() { |
| 3019 Source source = addSource(EngineTestCase.createSource([ |
| 3020 "class A {", |
| 3021 " final int a;", |
| 3022 " const A(String p) : a = 5 & p;", |
| 3023 "}"])); |
| 3024 resolve(source); |
| 3025 assertErrors(source, [ |
| 3026 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, |
| 3027 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 3028 verify([source]); |
| 3029 } |
| 3030 |
| 3031 void test_nonConstValueInInitializer_binary_notNum() { |
| 3032 Source source = addSource(EngineTestCase.createSource([ |
| 3033 "class A {", |
| 3034 " final int a;", |
| 3035 " const A(String p) : a = 5 + p;", |
| 3036 "}"])); |
| 3037 resolve(source); |
| 3038 assertErrors(source, [ |
| 3039 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, |
| 3040 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 3041 verify([source]); |
| 3042 } |
| 3043 |
| 3044 void test_nonConstValueInInitializer_field() { |
| 3045 Source source = addSource(EngineTestCase.createSource([ |
| 3046 "class A {", |
| 3047 " static int C;", |
| 3048 " final int a;", |
| 3049 " const A() : a = C;", |
| 3050 "}"])); |
| 3051 resolve(source); |
| 3052 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER
]); |
| 3053 verify([source]); |
| 3054 } |
| 3055 |
| 3056 void test_nonConstValueInInitializer_instanceCreation() { |
| 3057 Source source = addSource(EngineTestCase.createSource([ |
| 3058 "class A {", |
| 3059 " A();", |
| 3060 "}", |
| 3061 "class B {", |
| 3062 " const B() : a = new A();", |
| 3063 " final a;", |
| 3064 "}", |
| 3065 "var b = const B();"])); |
| 3066 resolve(source); |
| 3067 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER
]); |
| 3068 verify([source]); |
| 3069 } |
| 3070 |
| 3071 void test_nonConstValueInInitializer_redirecting() { |
| 3072 Source source = addSource(EngineTestCase.createSource([ |
| 3073 "class A {", |
| 3074 " static var C;", |
| 3075 " const A.named(p);", |
| 3076 " const A() : this.named(C);", |
| 3077 "}"])); |
| 3078 resolve(source); |
| 3079 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER
]); |
| 3080 verify([source]); |
| 3081 } |
| 3082 |
| 3083 void test_nonConstValueInInitializer_super() { |
| 3084 Source source = addSource(EngineTestCase.createSource([ |
| 3085 "class A {", |
| 3086 " const A(p);", |
| 3087 "}", |
| 3088 "class B extends A {", |
| 3089 " static var C;", |
| 3090 " const B() : super(C);", |
| 3091 "}"])); |
| 3092 resolve(source); |
| 3093 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER
]); |
| 3094 verify([source]); |
| 3095 } |
| 3096 |
| 3097 void test_nonConstValueInInitializerFromDeferredLibrary_field() { |
| 3098 resolveWithAndWithoutExperimental(<String> [ |
| 3099 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 3100 EngineTestCase.createSource([ |
| 3101 "library root;", |
| 3102 "import 'lib1.dart' deferred as a;", |
| 3103 "class A {", |
| 3104 " final int x;", |
| 3105 " const A() : x = a.c;", |
| 3106 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_
LIBRARY]); |
| 3107 } |
| 3108 |
| 3109 void test_nonConstValueInInitializerFromDeferredLibrary_field_nested() { |
| 3110 resolveWithAndWithoutExperimental(<String> [ |
| 3111 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 3112 EngineTestCase.createSource([ |
| 3113 "library root;", |
| 3114 "import 'lib1.dart' deferred as a;", |
| 3115 "class A {", |
| 3116 " final int x;", |
| 3117 " const A() : x = a.c + 1;", |
| 3118 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_
LIBRARY]); |
| 3119 } |
| 3120 |
| 3121 void test_nonConstValueInInitializerFromDeferredLibrary_redirecting() { |
| 3122 resolveWithAndWithoutExperimental(<String> [ |
| 3123 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 3124 EngineTestCase.createSource([ |
| 3125 "library root;", |
| 3126 "import 'lib1.dart' deferred as a;", |
| 3127 "class A {", |
| 3128 " const A.named(p);", |
| 3129 " const A() : this.named(a.c);", |
| 3130 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_
LIBRARY]); |
| 3131 } |
| 3132 |
| 3133 void test_nonConstValueInInitializerFromDeferredLibrary_super() { |
| 3134 resolveWithAndWithoutExperimental(<String> [ |
| 3135 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), |
| 3136 EngineTestCase.createSource([ |
| 3137 "library root;", |
| 3138 "import 'lib1.dart' deferred as a;", |
| 3139 "class A {", |
| 3140 " const A(p);", |
| 3141 "}", |
| 3142 "class B extends A {", |
| 3143 " const B() : super(a.c);", |
| 3144 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E
rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_
LIBRARY]); |
| 3145 } |
| 3146 |
| 3147 void test_nonGenerativeConstructor_explicit() { |
| 3148 Source source = addSource(EngineTestCase.createSource([ |
| 3149 "class A {", |
| 3150 " factory A.named() {}", |
| 3151 "}", |
| 3152 "class B extends A {", |
| 3153 " B() : super.named();", |
| 3154 "}"])); |
| 3155 resolve(source); |
| 3156 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
| 3157 verify([source]); |
| 3158 } |
| 3159 |
| 3160 void test_nonGenerativeConstructor_implicit() { |
| 3161 Source source = addSource(EngineTestCase.createSource([ |
| 3162 "class A {", |
| 3163 " factory A() {}", |
| 3164 "}", |
| 3165 "class B extends A {", |
| 3166 " B();", |
| 3167 "}"])); |
| 3168 resolve(source); |
| 3169 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
| 3170 verify([source]); |
| 3171 } |
| 3172 |
| 3173 void test_nonGenerativeConstructor_implicit2() { |
| 3174 Source source = addSource(EngineTestCase.createSource([ |
| 3175 "class A {", |
| 3176 " factory A() {}", |
| 3177 "}", |
| 3178 "class B extends A {", |
| 3179 "}"])); |
| 3180 resolve(source); |
| 3181 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
| 3182 verify([source]); |
| 3183 } |
| 3184 |
| 3185 void test_notEnoughRequiredArguments_const() { |
| 3186 Source source = addSource(EngineTestCase.createSource([ |
| 3187 "class A {", |
| 3188 " const A(int p);", |
| 3189 "}", |
| 3190 "main() {", |
| 3191 " const A();", |
| 3192 "}"])); |
| 3193 resolve(source); |
| 3194 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
| 3195 verify([source]); |
| 3196 } |
| 3197 |
| 3198 void test_notEnoughRequiredArguments_const_super() { |
| 3199 Source source = addSource(EngineTestCase.createSource([ |
| 3200 "class A {", |
| 3201 " const A(int p);", |
| 3202 "}", |
| 3203 "class B extends A {", |
| 3204 " const B() : super();", |
| 3205 "}"])); |
| 3206 resolve(source); |
| 3207 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
| 3208 verify([source]); |
| 3209 } |
| 3210 |
| 3211 void test_optionalParameterInOperator_named() { |
| 3212 Source source = addSource(EngineTestCase.createSource(["class A {", " opera
tor +({p}) {}", "}"])); |
| 3213 resolve(source); |
| 3214 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); |
| 3215 verify([source]); |
| 3216 } |
| 3217 |
| 3218 void test_optionalParameterInOperator_positional() { |
| 3219 Source source = addSource(EngineTestCase.createSource(["class A {", " opera
tor +([p]) {}", "}"])); |
| 3220 resolve(source); |
| 3221 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); |
| 3222 verify([source]); |
| 3223 } |
| 3224 |
| 3225 void test_partOfNonPart() { |
| 3226 Source source = addSource(EngineTestCase.createSource(["library l1;", "part
'l2.dart';"])); |
| 3227 addNamedSource("/l2.dart", EngineTestCase.createSource(["library l2;"])); |
| 3228 resolve(source); |
| 3229 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]); |
| 3230 verify([source]); |
| 3231 } |
| 3232 |
| 3233 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { |
| 3234 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl
ass A{}"])); |
| 3235 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "typedef p();", "p.A a;"])); |
| 3236 resolve(source); |
| 3237 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME
MBER]); |
| 3238 verify([source]); |
| 3239 } |
| 3240 |
| 3241 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { |
| 3242 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl
ass A{}"])); |
| 3243 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "p() {}", "p.A a;"])); |
| 3244 resolve(source); |
| 3245 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME
MBER]); |
| 3246 verify([source]); |
| 3247 } |
| 3248 |
| 3249 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { |
| 3250 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl
ass A{}"])); |
| 3251 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "var p = null;", "p.A a;"])); |
| 3252 resolve(source); |
| 3253 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME
MBER]); |
| 3254 verify([source]); |
| 3255 } |
| 3256 |
| 3257 void test_prefixCollidesWithTopLevelMembers_type() { |
| 3258 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl
ass A{}"])); |
| 3259 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as
p;", "class p {}", "p.A a;"])); |
| 3260 resolve(source); |
| 3261 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME
MBER]); |
| 3262 verify([source]); |
| 3263 } |
| 3264 |
| 3265 void test_privateOptionalParameter() { |
| 3266 Source source = addSource(EngineTestCase.createSource(["f({var _p}) {}"])); |
| 3267 resolve(source); |
| 3268 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
| 3269 verify([source]); |
| 3270 } |
| 3271 |
| 3272 void test_privateOptionalParameter_fieldFormal() { |
| 3273 Source source = addSource(EngineTestCase.createSource(["class A {", " var _
p;", " A({this._p: 0});", "}"])); |
| 3274 resolve(source); |
| 3275 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
| 3276 verify([source]); |
| 3277 } |
| 3278 |
| 3279 void test_privateOptionalParameter_withDefaultValue() { |
| 3280 Source source = addSource(EngineTestCase.createSource(["f({_p : 0}) {}"])); |
| 3281 resolve(source); |
| 3282 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
| 3283 verify([source]); |
| 3284 } |
| 3285 |
| 3286 void test_recursiveConstructorRedirect() { |
| 3287 Source source = addSource(EngineTestCase.createSource([ |
| 3288 "class A {", |
| 3289 " A.a() : this.b();", |
| 3290 " A.b() : this.a();", |
| 3291 "}"])); |
| 3292 resolve(source); |
| 3293 assertErrors(source, [ |
| 3294 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, |
| 3295 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); |
| 3296 verify([source]); |
| 3297 } |
| 3298 |
| 3299 void test_recursiveConstructorRedirect_directSelfReference() { |
| 3300 Source source = addSource(EngineTestCase.createSource(["class A {", " A() :
this();", "}"])); |
| 3301 resolve(source); |
| 3302 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); |
| 3303 verify([source]); |
| 3304 } |
| 3305 |
| 3306 void test_recursiveFactoryRedirect() { |
| 3307 Source source = addSource(EngineTestCase.createSource([ |
| 3308 "class A implements B {", |
| 3309 " factory A() = C;", |
| 3310 "}", |
| 3311 "class B implements C {", |
| 3312 " factory B() = A;", |
| 3313 "}", |
| 3314 "class C implements A {", |
| 3315 " factory C() = B;", |
| 3316 "}"])); |
| 3317 resolve(source); |
| 3318 assertErrors(source, [ |
| 3319 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3320 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3321 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3322 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3323 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3324 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3325 verify([source]); |
| 3326 } |
| 3327 |
| 3328 void test_recursiveFactoryRedirect_directSelfReference() { |
| 3329 Source source = addSource(EngineTestCase.createSource(["class A {", " facto
ry A() = A;", "}"])); |
| 3330 resolve(source); |
| 3331 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); |
| 3332 verify([source]); |
| 3333 } |
| 3334 |
| 3335 void test_recursiveFactoryRedirect_generic() { |
| 3336 Source source = addSource(EngineTestCase.createSource([ |
| 3337 "class A<T> implements B<T> {", |
| 3338 " factory A() = C;", |
| 3339 "}", |
| 3340 "class B<T> implements C<T> {", |
| 3341 " factory B() = A;", |
| 3342 "}", |
| 3343 "class C<T> implements A<T> {", |
| 3344 " factory C() = B;", |
| 3345 "}"])); |
| 3346 resolve(source); |
| 3347 assertErrors(source, [ |
| 3348 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3349 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3350 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3351 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3352 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3353 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3354 verify([source]); |
| 3355 } |
| 3356 |
| 3357 void test_recursiveFactoryRedirect_named() { |
| 3358 Source source = addSource(EngineTestCase.createSource([ |
| 3359 "class A implements B {", |
| 3360 " factory A.nameA() = C.nameC;", |
| 3361 "}", |
| 3362 "class B implements C {", |
| 3363 " factory B.nameB() = A.nameA;", |
| 3364 "}", |
| 3365 "class C implements A {", |
| 3366 " factory C.nameC() = B.nameB;", |
| 3367 "}"])); |
| 3368 resolve(source); |
| 3369 assertErrors(source, [ |
| 3370 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3371 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3372 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3373 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3374 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3375 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3376 verify([source]); |
| 3377 } |
| 3378 |
| 3379 /** |
| 3380 * "A" references "C" which has cycle with "B". But we should not report probl
em for "A" - it is |
| 3381 * not the part of a cycle. |
| 3382 */ |
| 3383 void test_recursiveFactoryRedirect_outsideCycle() { |
| 3384 Source source = addSource(EngineTestCase.createSource([ |
| 3385 "class A {", |
| 3386 " factory A() = C;", |
| 3387 "}", |
| 3388 "class B implements C {", |
| 3389 " factory B() = C;", |
| 3390 "}", |
| 3391 "class C implements A, B {", |
| 3392 " factory C() = B;", |
| 3393 "}"])); |
| 3394 resolve(source); |
| 3395 assertErrors(source, [ |
| 3396 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3397 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
| 3398 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3399 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3400 verify([source]); |
| 3401 } |
| 3402 |
| 3403 void test_recursiveInterfaceInheritance_extends() { |
| 3404 Source source = addSource(EngineTestCase.createSource(["class A extends B {}
", "class B extends A {}"])); |
| 3405 resolve(source); |
| 3406 assertErrors(source, [ |
| 3407 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3408 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3409 verify([source]); |
| 3410 } |
| 3411 |
| 3412 void test_recursiveInterfaceInheritance_extends_implements() { |
| 3413 Source source = addSource(EngineTestCase.createSource(["class A extends B {}
", "class B implements A {}"])); |
| 3414 resolve(source); |
| 3415 assertErrors(source, [ |
| 3416 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3417 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3418 verify([source]); |
| 3419 } |
| 3420 |
| 3421 void test_recursiveInterfaceInheritance_implements() { |
| 3422 Source source = addSource(EngineTestCase.createSource(["class A implements B
{}", "class B implements A {}"])); |
| 3423 resolve(source); |
| 3424 assertErrors(source, [ |
| 3425 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3426 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3427 verify([source]); |
| 3428 } |
| 3429 |
| 3430 void test_recursiveInterfaceInheritance_mixin() { |
| 3431 Source source = addSource(EngineTestCase.createSource([ |
| 3432 "class M1 = Object with M2;", |
| 3433 "class M2 = Object with M1;"])); |
| 3434 resolve(source); |
| 3435 assertErrors(source, [ |
| 3436 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3437 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3438 verify([source]); |
| 3439 } |
| 3440 |
| 3441 void test_recursiveInterfaceInheritance_tail() { |
| 3442 Source source = addSource(EngineTestCase.createSource([ |
| 3443 "abstract class A implements A {}", |
| 3444 "class B implements A {}"])); |
| 3445 resolve(source); |
| 3446 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B
ASE_CASE_IMPLEMENTS]); |
| 3447 verify([source]); |
| 3448 } |
| 3449 |
| 3450 void test_recursiveInterfaceInheritance_tail2() { |
| 3451 Source source = addSource(EngineTestCase.createSource([ |
| 3452 "abstract class A implements B {}", |
| 3453 "abstract class B implements A {}", |
| 3454 "class C implements A {}"])); |
| 3455 resolve(source); |
| 3456 assertErrors(source, [ |
| 3457 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3458 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3459 verify([source]); |
| 3460 } |
| 3461 |
| 3462 void test_recursiveInterfaceInheritance_tail3() { |
| 3463 Source source = addSource(EngineTestCase.createSource([ |
| 3464 "abstract class A implements B {}", |
| 3465 "abstract class B implements C {}", |
| 3466 "abstract class C implements A {}", |
| 3467 "class D implements A {}"])); |
| 3468 resolve(source); |
| 3469 assertErrors(source, [ |
| 3470 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3471 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 3472 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); |
| 3473 verify([source]); |
| 3474 } |
| 3475 |
| 3476 void test_recursiveInterfaceInheritanceBaseCaseExtends() { |
| 3477 Source source = addSource(EngineTestCase.createSource(["class A extends A {}
"])); |
| 3478 resolve(source); |
| 3479 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B
ASE_CASE_EXTENDS]); |
| 3480 verify([source]); |
| 3481 } |
| 3482 |
| 3483 void test_recursiveInterfaceInheritanceBaseCaseImplements() { |
| 3484 Source source = addSource(EngineTestCase.createSource(["class A implements A
{}"])); |
| 3485 resolve(source); |
| 3486 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B
ASE_CASE_IMPLEMENTS]); |
| 3487 verify([source]); |
| 3488 } |
| 3489 |
| 3490 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() { |
| 3491 Source source = addSource(EngineTestCase.createSource([ |
| 3492 "class A {}", |
| 3493 "class M {}", |
| 3494 "class B = A with M implements B;"])); |
| 3495 resolve(source); |
| 3496 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B
ASE_CASE_IMPLEMENTS]); |
| 3497 verify([source]); |
| 3498 } |
| 3499 |
| 3500 void test_recursiveInterfaceInheritanceBaseCaseWith() { |
| 3501 Source source = addSource(EngineTestCase.createSource(["class M = Object wit
h M;"])); |
| 3502 resolve(source); |
| 3503 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B
ASE_CASE_WITH]); |
| 3504 verify([source]); |
| 3505 } |
| 3506 |
| 3507 void test_redirectGenerativeToMissingConstructor() { |
| 3508 Source source = addSource(EngineTestCase.createSource(["class A {", " A() :
this.noSuchConstructor();", "}"])); |
| 3509 resolve(source); |
| 3510 assertErrors(source, [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CO
NSTRUCTOR]); |
| 3511 } |
| 3512 |
| 3513 void test_redirectGenerativeToNonGenerativeConstructor() { |
| 3514 Source source = addSource(EngineTestCase.createSource([ |
| 3515 "class A {", |
| 3516 " A() : this.x();", |
| 3517 " factory A.x() => null;", |
| 3518 "}"])); |
| 3519 resolve(source); |
| 3520 assertErrors(source, [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERA
TIVE_CONSTRUCTOR]); |
| 3521 verify([source]); |
| 3522 } |
| 3523 |
| 3524 void test_redirectToMissingConstructor_named() { |
| 3525 Source source = addSource(EngineTestCase.createSource([ |
| 3526 "class A implements B{", |
| 3527 " A() {}", |
| 3528 "}", |
| 3529 "class B {", |
| 3530 " const factory B() = A.name;", |
| 3531 "}"])); |
| 3532 resolve(source); |
| 3533 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR])
; |
| 3534 } |
| 3535 |
| 3536 void test_redirectToMissingConstructor_unnamed() { |
| 3537 Source source = addSource(EngineTestCase.createSource([ |
| 3538 "class A implements B{", |
| 3539 " A.name() {}", |
| 3540 "}", |
| 3541 "class B {", |
| 3542 " const factory B() = A;", |
| 3543 "}"])); |
| 3544 resolve(source); |
| 3545 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR])
; |
| 3546 } |
| 3547 |
| 3548 void test_redirectToNonClass_notAType() { |
| 3549 Source source = addSource(EngineTestCase.createSource(["int A;", "class B {"
, " const factory B() = A;", "}"])); |
| 3550 resolve(source); |
| 3551 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); |
| 3552 verify([source]); |
| 3553 } |
| 3554 |
| 3555 void test_redirectToNonClass_undefinedIdentifier() { |
| 3556 Source source = addSource(EngineTestCase.createSource(["class B {", " const
factory B() = A;", "}"])); |
| 3557 resolve(source); |
| 3558 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); |
| 3559 verify([source]); |
| 3560 } |
| 3561 |
| 3562 void test_redirectToNonConstConstructor() { |
| 3563 Source source = addSource(EngineTestCase.createSource([ |
| 3564 "class A {", |
| 3565 " A.a() {}", |
| 3566 " const factory A.b() = A.a;", |
| 3567 "}"])); |
| 3568 resolve(source); |
| 3569 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR
]); |
| 3570 verify([source]); |
| 3571 } |
| 3572 |
| 3573 void test_referencedBeforeDeclaration_hideInBlock_function() { |
| 3574 Source source = addSource(EngineTestCase.createSource([ |
| 3575 "var v = 1;", |
| 3576 "main() {", |
| 3577 " print(v);", |
| 3578 " v() {}", |
| 3579 "}", |
| 3580 "print(x) {}"])); |
| 3581 resolve(source); |
| 3582 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
| 3583 } |
| 3584 |
| 3585 void test_referencedBeforeDeclaration_hideInBlock_local() { |
| 3586 Source source = addSource(EngineTestCase.createSource([ |
| 3587 "var v = 1;", |
| 3588 "main() {", |
| 3589 " print(v);", |
| 3590 " var v = 2;", |
| 3591 "}", |
| 3592 "print(x) {}"])); |
| 3593 resolve(source); |
| 3594 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
| 3595 } |
| 3596 |
| 3597 void test_referencedBeforeDeclaration_hideInBlock_subBlock() { |
| 3598 Source source = addSource(EngineTestCase.createSource([ |
| 3599 "var v = 1;", |
| 3600 "main() {", |
| 3601 " {", |
| 3602 " print(v);", |
| 3603 " }", |
| 3604 " var v = 2;", |
| 3605 "}", |
| 3606 "print(x) {}"])); |
| 3607 resolve(source); |
| 3608 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
| 3609 } |
| 3610 |
| 3611 void test_referencedBeforeDeclaration_inInitializer_closure() { |
| 3612 Source source = addSource(EngineTestCase.createSource(["main() {", " var v
= () => v;", "}"])); |
| 3613 resolve(source); |
| 3614 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
| 3615 } |
| 3616 |
| 3617 void test_referencedBeforeDeclaration_inInitializer_directly() { |
| 3618 Source source = addSource(EngineTestCase.createSource(["main() {", " var v
= v;", "}"])); |
| 3619 resolve(source); |
| 3620 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
| 3621 } |
| 3622 |
| 3623 void test_rethrowOutsideCatch() { |
| 3624 Source source = addSource(EngineTestCase.createSource(["f() {", " rethrow;"
, "}"])); |
| 3625 resolve(source); |
| 3626 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]); |
| 3627 verify([source]); |
| 3628 } |
| 3629 |
| 3630 void test_returnInGenerativeConstructor() { |
| 3631 Source source = addSource(EngineTestCase.createSource(["class A {", " A() {
return 0; }", "}"])); |
| 3632 resolve(source); |
| 3633 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]
); |
| 3634 verify([source]); |
| 3635 } |
| 3636 |
| 3637 void test_returnInGenerativeConstructor_expressionFunctionBody() { |
| 3638 Source source = addSource(EngineTestCase.createSource(["class A {", " A() =
> null;", "}"])); |
| 3639 resolve(source); |
| 3640 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]
); |
| 3641 verify([source]); |
| 3642 } |
| 3643 |
| 3644 void test_returnInGenerator_asyncStar() { |
| 3645 resetWithAsync(); |
| 3646 Source source = addSource(EngineTestCase.createSource(["f() async* {", " re
turn 0;", "}"])); |
| 3647 resolve(source); |
| 3648 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); |
| 3649 verify([source]); |
| 3650 } |
| 3651 |
| 3652 void test_returnInGenerator_syncStar() { |
| 3653 resetWithAsync(); |
| 3654 Source source = addSource(EngineTestCase.createSource(["f() sync* {", " ret
urn 0;", "}"])); |
| 3655 resolve(source); |
| 3656 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); |
| 3657 verify([source]); |
| 3658 } |
| 3659 |
| 3660 void test_sharedDeferredPrefix() { |
| 3661 resolveWithAndWithoutExperimental(<String> [ |
| 3662 EngineTestCase.createSource(["library lib1;", "f1() {}"]), |
| 3663 EngineTestCase.createSource(["library lib2;", "f2() {}"]), |
| 3664 EngineTestCase.createSource([ |
| 3665 "library root;", |
| 3666 "import 'lib1.dart' deferred as lib;", |
| 3667 "import 'lib2.dart' as lib;", |
| 3668 "main() { lib.f1(); lib.f2(); }"])], <ErrorCode> [ParserErrorCode.DEFERR
ED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.SHARED_DEFERRED_PRE
FIX]); |
| 3669 } |
| 3670 |
| 3671 void test_superInInvalidContext_binaryExpression() { |
| 3672 Source source = addSource(EngineTestCase.createSource(["var v = super + 0;"]
)); |
| 3673 resolve(source); |
| 3674 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3675 // no verify(), 'super.v' is not resolved |
| 3676 } |
| 3677 |
| 3678 void test_superInInvalidContext_constructorFieldInitializer() { |
| 3679 Source source = addSource(EngineTestCase.createSource([ |
| 3680 "class A {", |
| 3681 " m() {}", |
| 3682 "}", |
| 3683 "class B extends A {", |
| 3684 " var f;", |
| 3685 " B() : f = super.m();", |
| 3686 "}"])); |
| 3687 resolve(source); |
| 3688 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3689 // no verify(), 'super.m' is not resolved |
| 3690 } |
| 3691 |
| 3692 void test_superInInvalidContext_factoryConstructor() { |
| 3693 Source source = addSource(EngineTestCase.createSource([ |
| 3694 "class A {", |
| 3695 " m() {}", |
| 3696 "}", |
| 3697 "class B extends A {", |
| 3698 " factory B() {", |
| 3699 " super.m();", |
| 3700 " }", |
| 3701 "}"])); |
| 3702 resolve(source); |
| 3703 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3704 // no verify(), 'super.m' is not resolved |
| 3705 } |
| 3706 |
| 3707 void test_superInInvalidContext_instanceVariableInitializer() { |
| 3708 Source source = addSource(EngineTestCase.createSource([ |
| 3709 "class A {", |
| 3710 " var a;", |
| 3711 "}", |
| 3712 "class B extends A {", |
| 3713 " var b = super.a;", |
| 3714 "}"])); |
| 3715 resolve(source); |
| 3716 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3717 // no verify(), 'super.a' is not resolved |
| 3718 } |
| 3719 |
| 3720 void test_superInInvalidContext_staticMethod() { |
| 3721 Source source = addSource(EngineTestCase.createSource([ |
| 3722 "class A {", |
| 3723 " static m() {}", |
| 3724 "}", |
| 3725 "class B extends A {", |
| 3726 " static n() { return super.m(); }", |
| 3727 "}"])); |
| 3728 resolve(source); |
| 3729 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3730 // no verify(), 'super.m' is not resolved |
| 3731 } |
| 3732 |
| 3733 void test_superInInvalidContext_staticVariableInitializer() { |
| 3734 Source source = addSource(EngineTestCase.createSource([ |
| 3735 "class A {", |
| 3736 " static int a = 0;", |
| 3737 "}", |
| 3738 "class B extends A {", |
| 3739 " static int b = super.a;", |
| 3740 "}"])); |
| 3741 resolve(source); |
| 3742 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3743 // no verify(), 'super.a' is not resolved |
| 3744 } |
| 3745 |
| 3746 void test_superInInvalidContext_topLevelFunction() { |
| 3747 Source source = addSource(EngineTestCase.createSource(["f() {", " super.f()
;", "}"])); |
| 3748 resolve(source); |
| 3749 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3750 // no verify(), 'super.f' is not resolved |
| 3751 } |
| 3752 |
| 3753 void test_superInInvalidContext_topLevelVariableInitializer() { |
| 3754 Source source = addSource(EngineTestCase.createSource(["var v = super.y;"]))
; |
| 3755 resolve(source); |
| 3756 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 3757 // no verify(), 'super.y' is not resolved |
| 3758 } |
| 3759 |
| 3760 void test_superInRedirectingConstructor_redirectionSuper() { |
| 3761 Source source = addSource(EngineTestCase.createSource([ |
| 3762 "class A {}", |
| 3763 "class B {", |
| 3764 " B() : this.name(), super();", |
| 3765 " B.name() {}", |
| 3766 "}"])); |
| 3767 resolve(source); |
| 3768 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]
); |
| 3769 verify([source]); |
| 3770 } |
| 3771 |
| 3772 void test_superInRedirectingConstructor_superRedirection() { |
| 3773 Source source = addSource(EngineTestCase.createSource([ |
| 3774 "class A {}", |
| 3775 "class B {", |
| 3776 " B() : super(), this.name();", |
| 3777 " B.name() {}", |
| 3778 "}"])); |
| 3779 resolve(source); |
| 3780 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]
); |
| 3781 verify([source]); |
| 3782 } |
| 3783 |
| 3784 void test_symbol_constructor_badArgs() { |
| 3785 Source source = addSource(EngineTestCase.createSource([ |
| 3786 "var s1 = const Symbol('3');", |
| 3787 "var s2 = const Symbol(3);", |
| 3788 "var s3 = const Symbol();", |
| 3789 "var s4 = const Symbol('x', 'y');", |
| 3790 "var s5 = const Symbol('x', foo: 'x');"])); |
| 3791 resolve(source); |
| 3792 assertErrors(source, [ |
| 3793 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 3794 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 3795 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
| 3796 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, |
| 3797 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, |
| 3798 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); |
| 3799 verify([source]); |
| 3800 } |
| 3801 |
| 3802 void test_typeAliasCannotReferenceItself_11987() { |
| 3803 Source source = addSource(EngineTestCase.createSource([ |
| 3804 "typedef void F(List<G> l);", |
| 3805 "typedef void G(List<F> l);", |
| 3806 "main() {", |
| 3807 " F foo(G g) => g;", |
| 3808 "}"])); |
| 3809 resolve(source); |
| 3810 assertErrors(source, [ |
| 3811 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, |
| 3812 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, |
| 3813 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
| 3814 verify([source]); |
| 3815 } |
| 3816 |
| 3817 void test_typeAliasCannotReferenceItself_parameterType_named() { |
| 3818 Source source = addSource(EngineTestCase.createSource(["typedef A({A a});"])
); |
| 3819 resolve(source); |
| 3820 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3821 verify([source]); |
| 3822 } |
| 3823 |
| 3824 void test_typeAliasCannotReferenceItself_parameterType_positional() { |
| 3825 Source source = addSource(EngineTestCase.createSource(["typedef A([A a]);"])
); |
| 3826 resolve(source); |
| 3827 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3828 verify([source]); |
| 3829 } |
| 3830 |
| 3831 void test_typeAliasCannotReferenceItself_parameterType_required() { |
| 3832 Source source = addSource(EngineTestCase.createSource(["typedef A(A a);"])); |
| 3833 resolve(source); |
| 3834 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3835 verify([source]); |
| 3836 } |
| 3837 |
| 3838 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() { |
| 3839 Source source = addSource(EngineTestCase.createSource(["typedef A(List<A> a)
;"])); |
| 3840 resolve(source); |
| 3841 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3842 verify([source]); |
| 3843 } |
| 3844 |
| 3845 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() { |
| 3846 Source source = addSource(EngineTestCase.createSource([ |
| 3847 "typedef C A();", |
| 3848 "typedef A B();", |
| 3849 "class C {", |
| 3850 " B a;", |
| 3851 "}"])); |
| 3852 resolve(source); |
| 3853 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3854 verify([source]); |
| 3855 } |
| 3856 |
| 3857 void test_typeAliasCannotReferenceItself_returnType() { |
| 3858 Source source = addSource(EngineTestCase.createSource(["typedef A A();"])); |
| 3859 resolve(source); |
| 3860 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3861 verify([source]); |
| 3862 } |
| 3863 |
| 3864 void test_typeAliasCannotReferenceItself_returnType_indirect() { |
| 3865 Source source = addSource(EngineTestCase.createSource(["typedef B A();", "ty
pedef A B();"])); |
| 3866 resolve(source); |
| 3867 assertErrors(source, [ |
| 3868 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, |
| 3869 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
| 3870 verify([source]); |
| 3871 } |
| 3872 |
| 3873 void test_typeAliasCannotReferenceItself_typeVariableBounds() { |
| 3874 Source source = addSource(EngineTestCase.createSource(["typedef A<T extends
A>();"])); |
| 3875 resolve(source); |
| 3876 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL
F]); |
| 3877 verify([source]); |
| 3878 } |
| 3879 |
| 3880 void test_typeArgumentNotMatchingBounds_const() { |
| 3881 Source source = addSource(EngineTestCase.createSource([ |
| 3882 "class A {}", |
| 3883 "class B {}", |
| 3884 "class G<E extends A> {", |
| 3885 " const G();", |
| 3886 "}", |
| 3887 "f() { return const G<B>(); }"])); |
| 3888 resolve(source); |
| 3889 assertErrors(source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
]); |
| 3890 verify([source]); |
| 3891 } |
| 3892 |
| 3893 void test_undefinedClass_const() { |
| 3894 Source source = addSource(EngineTestCase.createSource(["f() {", " return co
nst A();", "}"])); |
| 3895 resolve(source); |
| 3896 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]); |
| 3897 verify([source]); |
| 3898 } |
| 3899 |
| 3900 void test_undefinedConstructorInInitializer_explicit_named() { |
| 3901 Source source = addSource(EngineTestCase.createSource([ |
| 3902 "class A {}", |
| 3903 "class B extends A {", |
| 3904 " B() : super.named();", |
| 3905 "}"])); |
| 3906 resolve(source); |
| 3907 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI
ZER]); |
| 3908 // no verify(), "super.named()" is not resolved |
| 3909 } |
| 3910 |
| 3911 void test_undefinedConstructorInInitializer_explicit_unnamed() { |
| 3912 Source source = addSource(EngineTestCase.createSource([ |
| 3913 "class A {", |
| 3914 " A.named() {}", |
| 3915 "}", |
| 3916 "class B extends A {", |
| 3917 " B() : super();", |
| 3918 "}"])); |
| 3919 resolve(source); |
| 3920 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI
ZER_DEFAULT]); |
| 3921 verify([source]); |
| 3922 } |
| 3923 |
| 3924 void test_undefinedConstructorInInitializer_implicit() { |
| 3925 Source source = addSource(EngineTestCase.createSource([ |
| 3926 "class A {", |
| 3927 " A.named() {}", |
| 3928 "}", |
| 3929 "class B extends A {", |
| 3930 " B();", |
| 3931 "}"])); |
| 3932 resolve(source); |
| 3933 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI
ZER_DEFAULT]); |
| 3934 verify([source]); |
| 3935 } |
| 3936 |
| 3937 void test_undefinedNamedParameter() { |
| 3938 Source source = addSource(EngineTestCase.createSource([ |
| 3939 "class A {", |
| 3940 " const A();", |
| 3941 "}", |
| 3942 "main() {", |
| 3943 " const A(p: 0);", |
| 3944 "}"])); |
| 3945 resolve(source); |
| 3946 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); |
| 3947 // no verify(), 'p' is not resolved |
| 3948 } |
| 3949 |
| 3950 void test_uriDoesNotExist_export() { |
| 3951 Source source = addSource(EngineTestCase.createSource(["export 'unknown.dart
';"])); |
| 3952 resolve(source); |
| 3953 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 3954 } |
| 3955 |
| 3956 void test_uriDoesNotExist_import() { |
| 3957 Source source = addSource(EngineTestCase.createSource(["import 'unknown.dart
';"])); |
| 3958 resolve(source); |
| 3959 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 3960 } |
| 3961 |
| 3962 void test_uriDoesNotExist_part() { |
| 3963 Source source = addSource(EngineTestCase.createSource(["part 'unknown.dart';
"])); |
| 3964 resolve(source); |
| 3965 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 3966 } |
| 3967 |
| 3968 void test_uriWithInterpolation_constant() { |
| 3969 Source source = addSource(EngineTestCase.createSource(["import 'stuff_\$plat
form.dart';"])); |
| 3970 resolve(source); |
| 3971 assertErrors(source, [ |
| 3972 CompileTimeErrorCode.URI_WITH_INTERPOLATION, |
| 3973 StaticWarningCode.UNDEFINED_IDENTIFIER]); |
| 3974 // We cannot verify resolution with an unresolvable URI: 'stuff_$platform.da
rt' |
| 3975 } |
| 3976 |
| 3977 void test_uriWithInterpolation_nonConstant() { |
| 3978 Source source = addSource(EngineTestCase.createSource(["library lib;", "part
'\${'a'}.dart';"])); |
| 3979 resolve(source); |
| 3980 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]); |
| 3981 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart' |
| 3982 } |
| 3983 |
| 3984 void test_wrongNumberOfParametersForOperator_minus() { |
| 3985 Source source = addSource(EngineTestCase.createSource(["class A {", " opera
tor -(a, b) {}", "}"])); |
| 3986 resolve(source); |
| 3987 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OP
ERATOR_MINUS]); |
| 3988 verify([source]); |
| 3989 reset(); |
| 3990 } |
| 3991 |
| 3992 void test_wrongNumberOfParametersForOperator_tilde() { |
| 3993 _check_wrongNumberOfParametersForOperator("~", "a"); |
| 3994 _check_wrongNumberOfParametersForOperator("~", "a, b"); |
| 3995 } |
| 3996 |
| 3997 void test_wrongNumberOfParametersForOperator1() { |
| 3998 _check_wrongNumberOfParametersForOperator1("<"); |
| 3999 _check_wrongNumberOfParametersForOperator1(">"); |
| 4000 _check_wrongNumberOfParametersForOperator1("<="); |
| 4001 _check_wrongNumberOfParametersForOperator1(">="); |
| 4002 _check_wrongNumberOfParametersForOperator1("+"); |
| 4003 _check_wrongNumberOfParametersForOperator1("/"); |
| 4004 _check_wrongNumberOfParametersForOperator1("~/"); |
| 4005 _check_wrongNumberOfParametersForOperator1("*"); |
| 4006 _check_wrongNumberOfParametersForOperator1("%"); |
| 4007 _check_wrongNumberOfParametersForOperator1("|"); |
| 4008 _check_wrongNumberOfParametersForOperator1("^"); |
| 4009 _check_wrongNumberOfParametersForOperator1("&"); |
| 4010 _check_wrongNumberOfParametersForOperator1("<<"); |
| 4011 _check_wrongNumberOfParametersForOperator1(">>"); |
| 4012 _check_wrongNumberOfParametersForOperator1("[]"); |
| 4013 } |
| 4014 |
| 4015 void test_wrongNumberOfParametersForSetter_function_named() { |
| 4016 Source source = addSource("set x({p}) {}"); |
| 4017 resolve(source); |
| 4018 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4019 verify([source]); |
| 4020 } |
| 4021 |
| 4022 void test_wrongNumberOfParametersForSetter_function_optional() { |
| 4023 Source source = addSource("set x([p]) {}"); |
| 4024 resolve(source); |
| 4025 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4026 verify([source]); |
| 4027 } |
| 4028 |
| 4029 void test_wrongNumberOfParametersForSetter_function_tooFew() { |
| 4030 Source source = addSource("set x() {}"); |
| 4031 resolve(source); |
| 4032 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4033 verify([source]); |
| 4034 } |
| 4035 |
| 4036 void test_wrongNumberOfParametersForSetter_function_tooMany() { |
| 4037 Source source = addSource("set x(a, b) {}"); |
| 4038 resolve(source); |
| 4039 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4040 verify([source]); |
| 4041 } |
| 4042 |
| 4043 void test_wrongNumberOfParametersForSetter_method_named() { |
| 4044 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
({p}) {}", "}"])); |
| 4045 resolve(source); |
| 4046 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4047 verify([source]); |
| 4048 } |
| 4049 |
| 4050 void test_wrongNumberOfParametersForSetter_method_optional() { |
| 4051 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
([p]) {}", "}"])); |
| 4052 resolve(source); |
| 4053 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4054 verify([source]); |
| 4055 } |
| 4056 |
| 4057 void test_wrongNumberOfParametersForSetter_method_tooFew() { |
| 4058 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
() {}", "}"])); |
| 4059 resolve(source); |
| 4060 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4061 verify([source]); |
| 4062 } |
| 4063 |
| 4064 void test_wrongNumberOfParametersForSetter_method_tooMany() { |
| 4065 Source source = addSource(EngineTestCase.createSource(["class A {", " set x
(a, b) {}", "}"])); |
| 4066 resolve(source); |
| 4067 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE
TTER]); |
| 4068 verify([source]); |
| 4069 } |
| 4070 |
| 4071 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { |
| 4072 Source source = addSource("const C = ${expr};"); |
| 4073 resolve(source); |
| 4074 if (resolved) { |
| 4075 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 4076 verify([source]); |
| 4077 } else { |
| 4078 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 4079 // no verify(), 'null x' is not resolved |
| 4080 } |
| 4081 reset(); |
| 4082 } |
| 4083 |
| 4084 void _check_constEvalTypeBool_withParameter_binary(String expr) { |
| 4085 Source source = addSource(EngineTestCase.createSource([ |
| 4086 "class A {", |
| 4087 " final a;", |
| 4088 " const A(bool p) : a = ${expr};", |
| 4089 "}"])); |
| 4090 resolve(source); |
| 4091 assertErrors(source, [ |
| 4092 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
| 4093 StaticTypeWarningCode.NON_BOOL_OPERAND]); |
| 4094 verify([source]); |
| 4095 reset(); |
| 4096 } |
| 4097 |
| 4098 void _check_constEvalTypeInt_withParameter_binary(String expr) { |
| 4099 Source source = addSource(EngineTestCase.createSource([ |
| 4100 "class A {", |
| 4101 " final a;", |
| 4102 " const A(int p) : a = ${expr};", |
| 4103 "}"])); |
| 4104 resolve(source); |
| 4105 assertErrors(source, [ |
| 4106 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, |
| 4107 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 4108 verify([source]); |
| 4109 reset(); |
| 4110 } |
| 4111 |
| 4112 void _check_constEvalTypeNum_withParameter_binary(String expr) { |
| 4113 Source source = addSource(EngineTestCase.createSource([ |
| 4114 "class A {", |
| 4115 " final a;", |
| 4116 " const A(num p) : a = ${expr};", |
| 4117 "}"])); |
| 4118 resolve(source); |
| 4119 assertErrors(source, [ |
| 4120 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, |
| 4121 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 4122 verify([source]); |
| 4123 reset(); |
| 4124 } |
| 4125 |
| 4126 void _check_wrongNumberOfParametersForOperator(String name, String parameters)
{ |
| 4127 Source source = addSource(EngineTestCase.createSource(["class A {", " opera
tor ${name}(${parameters}) {}", "}"])); |
| 4128 resolve(source); |
| 4129 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OP
ERATOR]); |
| 4130 verify([source]); |
| 4131 reset(); |
| 4132 } |
| 4133 |
| 4134 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 4135 _check_wrongNumberOfParametersForOperator(name, ""); |
| 4136 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 4137 } |
| 4138 } |
| 4139 |
| 4140 main() { |
| 4141 _ut.groupSep = ' | '; |
| 4142 runReflectiveTests(CompileTimeErrorCodeTest); |
| 4143 } |
OLD | NEW |