| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--enable_type_checks --no_show_internal_names | 4 // VMOptions=--enable_type_checks --no_show_internal_names |
| 5 // | 5 // |
| 6 // Dart test program testing type checks. | 6 // Dart test program testing type checks. |
| 7 | 7 |
| 8 class TypeTest { | 8 class TypeTest { |
| 9 static test() { | 9 static test() { |
| 10 int result = 0; | 10 int result = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 return result; | 27 return result; |
| 28 } | 28 } |
| 29 | 29 |
| 30 static testSideEffect() { | 30 static testSideEffect() { |
| 31 int result = 0; | 31 int result = 0; |
| 32 int index() { | 32 int index() { |
| 33 result++; | 33 result++; |
| 34 return 0; | 34 return 0; |
| 35 } | 35 } |
| 36 try { | 36 try { |
| 37 List<int> a = new List<int>(1); | 37 List<int> a = new List<int>.fixedLength(1); |
| 38 a[0] = 0; | 38 a[0] = 0; |
| 39 a[index()]++; // Type check succeeds, but does not create side effects. | 39 a[index()]++; // Type check succeeds, but does not create side effects. |
| 40 Expect.equals(1, a[0]); | 40 Expect.equals(1, a[0]); |
| 41 } on TypeError catch (error) { | 41 } on TypeError catch (error) { |
| 42 result = 100; | 42 result = 100; |
| 43 } | 43 } |
| 44 return result; | 44 return result; |
| 45 } | 45 } |
| 46 | 46 |
| 47 static testArgument() { | 47 static testArgument() { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 Expect.equals("type_vm_test.dart", subs); | 370 Expect.equals("type_vm_test.dart", subs); |
| 371 Expect.equals(560, error.line); | 371 Expect.equals(560, error.line); |
| 372 Expect.equals(12, error.column); | 372 Expect.equals(12, error.column); |
| 373 } | 373 } |
| 374 return result; | 374 return result; |
| 375 } | 375 } |
| 376 | 376 |
| 377 static int testListAssigment() { | 377 static int testListAssigment() { |
| 378 int result = 0; | 378 int result = 0; |
| 379 { | 379 { |
| 380 var a = new List(5); | 380 var a = new List.fixedLength(5); |
| 381 List a0 = a; | 381 List a0 = a; |
| 382 List<Object> ao = a; | 382 List<Object> ao = a; |
| 383 List<int> ai = a; | 383 List<int> ai = a; |
| 384 List<num> an = a; | 384 List<num> an = a; |
| 385 List<String> as = a; | 385 List<String> as = a; |
| 386 } | 386 } |
| 387 { | 387 { |
| 388 var a = new List<Object>(5); | 388 var a = new List<Object>.fixedLength(5); |
| 389 List a0 = a; | 389 List a0 = a; |
| 390 List<Object> ao = a; | 390 List<Object> ao = a; |
| 391 try { | 391 try { |
| 392 List<int> ai = a; | 392 List<int> ai = a; |
| 393 } on TypeError catch (error) { | 393 } on TypeError catch (error) { |
| 394 result++; | 394 result++; |
| 395 Expect.equals("List<int>", error.dstType); | 395 Expect.equals("List<int>", error.dstType); |
| 396 Expect.equals("List<Object>", error.srcType); | 396 Expect.equals("List<Object>", error.srcType); |
| 397 Expect.equals("ai", error.dstName); | 397 Expect.equals("ai", error.dstName); |
| 398 int pos = error.url.lastIndexOf("/", error.url.length); | 398 int pos = error.url.lastIndexOf("/", error.url.length); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 if (pos == -1) { | 431 if (pos == -1) { |
| 432 pos = error.url.lastIndexOf("\\", error.url.length); | 432 pos = error.url.lastIndexOf("\\", error.url.length); |
| 433 } | 433 } |
| 434 String subs = error.url.substring(pos + 1, error.url.length); | 434 String subs = error.url.substring(pos + 1, error.url.length); |
| 435 Expect.equals("type_vm_test.dart", subs); | 435 Expect.equals("type_vm_test.dart", subs); |
| 436 Expect.equals(424, error.line); | 436 Expect.equals(424, error.line); |
| 437 Expect.equals(27, error.column); | 437 Expect.equals(27, error.column); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 { | 440 { |
| 441 var a = new List<int>(5); | 441 var a = new List<int>.fixedLength(5); |
| 442 List a0 = a; | 442 List a0 = a; |
| 443 List<Object> ao = a; | 443 List<Object> ao = a; |
| 444 List<int> ai = a; | 444 List<int> ai = a; |
| 445 List<num> an = a; | 445 List<num> an = a; |
| 446 try { | 446 try { |
| 447 List<String> as = a; | 447 List<String> as = a; |
| 448 } on TypeError catch (error) { | 448 } on TypeError catch (error) { |
| 449 result++; | 449 result++; |
| 450 Expect.equals("List<String>", error.dstType); | 450 Expect.equals("List<String>", error.dstType); |
| 451 Expect.equals("List<int>", error.srcType); | 451 Expect.equals("List<int>", error.srcType); |
| 452 Expect.equals("as", error.dstName); | 452 Expect.equals("as", error.dstName); |
| 453 int pos = error.url.lastIndexOf("/", error.url.length); | 453 int pos = error.url.lastIndexOf("/", error.url.length); |
| 454 if (pos == -1) { | 454 if (pos == -1) { |
| 455 pos = error.url.lastIndexOf("\\", error.url.length); | 455 pos = error.url.lastIndexOf("\\", error.url.length); |
| 456 } | 456 } |
| 457 String subs = error.url.substring(pos + 1, error.url.length); | 457 String subs = error.url.substring(pos + 1, error.url.length); |
| 458 Expect.equals("type_vm_test.dart", subs); | 458 Expect.equals("type_vm_test.dart", subs); |
| 459 Expect.equals(447, error.line); | 459 Expect.equals(447, error.line); |
| 460 Expect.equals(27, error.column); | 460 Expect.equals(27, error.column); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 { | 463 { |
| 464 var a = new List<num>(5); | 464 var a = new List<num>.fixedLength(5); |
| 465 List a0 = a; | 465 List a0 = a; |
| 466 List<Object> ao = a; | 466 List<Object> ao = a; |
| 467 try { | 467 try { |
| 468 List<int> ai = a; | 468 List<int> ai = a; |
| 469 } on TypeError catch (error) { | 469 } on TypeError catch (error) { |
| 470 result++; | 470 result++; |
| 471 Expect.equals("List<int>", error.dstType); | 471 Expect.equals("List<int>", error.dstType); |
| 472 Expect.equals("List<num>", error.srcType); | 472 Expect.equals("List<num>", error.srcType); |
| 473 Expect.equals("ai", error.dstName); | 473 Expect.equals("ai", error.dstName); |
| 474 int pos = error.url.lastIndexOf("/", error.url.length); | 474 int pos = error.url.lastIndexOf("/", error.url.length); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 492 if (pos == -1) { | 492 if (pos == -1) { |
| 493 pos = error.url.lastIndexOf("\\", error.url.length); | 493 pos = error.url.lastIndexOf("\\", error.url.length); |
| 494 } | 494 } |
| 495 String subs = error.url.substring(pos + 1, error.url.length); | 495 String subs = error.url.substring(pos + 1, error.url.length); |
| 496 Expect.equals("type_vm_test.dart", subs); | 496 Expect.equals("type_vm_test.dart", subs); |
| 497 Expect.equals(485, error.line); | 497 Expect.equals(485, error.line); |
| 498 Expect.equals(27, error.column); | 498 Expect.equals(27, error.column); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 { | 501 { |
| 502 var a = new List<String>(5); | 502 var a = new List<String>.fixedLength(5); |
| 503 List a0 = a; | 503 List a0 = a; |
| 504 List<Object> ao = a; | 504 List<Object> ao = a; |
| 505 try { | 505 try { |
| 506 List<int> ai = a; | 506 List<int> ai = a; |
| 507 } on TypeError catch (error) { | 507 } on TypeError catch (error) { |
| 508 result++; | 508 result++; |
| 509 Expect.equals("List<int>", error.dstType); | 509 Expect.equals("List<int>", error.dstType); |
| 510 Expect.equals("List<String>", error.srcType); | 510 Expect.equals("List<String>", error.srcType); |
| 511 Expect.equals("ai", error.dstName); | 511 Expect.equals("ai", error.dstName); |
| 512 int pos = error.url.lastIndexOf("/", error.url.length); | 512 int pos = error.url.lastIndexOf("/", error.url.length); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 class C { | 558 class C { |
| 559 factory C() { | 559 factory C() { |
| 560 return 1; // Implicit result type is 'C', not int. | 560 return 1; // Implicit result type is 'C', not int. |
| 561 } | 561 } |
| 562 } | 562 } |
| 563 | 563 |
| 564 | 564 |
| 565 main() { | 565 main() { |
| 566 TypeTest.testMain(); | 566 TypeTest.testMain(); |
| 567 } | 567 } |
| OLD | NEW |