OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 public void test_conflictingTypeVariableAndMember_setter() throws Exception { | 328 public void test_conflictingTypeVariableAndMember_setter() throws Exception { |
329 Source source = addSource(createSource(// | 329 Source source = addSource(createSource(// |
330 "class A<T> {", | 330 "class A<T> {", |
331 " set T(x) {}", | 331 " set T(x) {}", |
332 "}")); | 332 "}")); |
333 resolve(source); | 333 resolve(source); |
334 assertErrors(source, CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMB
ER); | 334 assertErrors(source, CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMB
ER); |
335 verify(source); | 335 verify(source); |
336 } | 336 } |
337 | 337 |
| 338 public void test_consistentCaseExpressionTypes_dynamic() throws Exception { |
| 339 // Even though A.S and S have a static type of "dynamic", we should see |
| 340 // that they match 'abc', because they are constant strings. |
| 341 Source source = addSource(createSource(// |
| 342 "class A {", |
| 343 " static const S = 'A.S';", |
| 344 "}", |
| 345 "", |
| 346 "const S = 'S';", |
| 347 "", |
| 348 "foo(var p) {", |
| 349 " switch (p) {", |
| 350 " case S:", |
| 351 " break;", |
| 352 " case A.S:", |
| 353 " break;", |
| 354 " case 'abc':", |
| 355 " break;", |
| 356 " }", |
| 357 "}")); |
| 358 resolve(source); |
| 359 assertNoErrors(source); |
| 360 verify(source); |
| 361 } |
| 362 |
338 public void test_constConstructorWithNonConstSuper_explicit() throws Exception
{ | 363 public void test_constConstructorWithNonConstSuper_explicit() throws Exception
{ |
339 Source source = addSource(createSource(// | 364 Source source = addSource(createSource(// |
340 "class A {", | 365 "class A {", |
341 " A();", | 366 " A();", |
342 "}", | 367 "}", |
343 "class B extends A {", | 368 "class B extends A {", |
344 " const B(): super();", | 369 " const B(): super();", |
345 "}")); | 370 "}")); |
346 resolve(source); | 371 resolve(source); |
347 assertErrors(source, CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_S
UPER); | 372 assertErrors(source, CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_S
UPER); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 " operator ==(other) => false;", | 673 " operator ==(other) => false;", |
649 "}", | 674 "}", |
650 "main() {", | 675 "main() {", |
651 " const {const A() : 0};", | 676 " const {const A() : 0};", |
652 "}")); | 677 "}")); |
653 resolve(source); | 678 resolve(source); |
654 assertErrors(source, CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPL
EMENTS_EQUALS); | 679 assertErrors(source, CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPL
EMENTS_EQUALS); |
655 verify(source); | 680 verify(source); |
656 } | 681 } |
657 | 682 |
| 683 public void test_constMapKeyTypeImplementsEquals_dynamic() throws Exception { |
| 684 // Note: static type of B.a is "dynamic", but actual type of the const |
| 685 // object is A. We need to make sure we examine the actual type when |
| 686 // deciding whether there is a problem with operator==. |
| 687 Source source = addSource(createSource(// |
| 688 "class A {", |
| 689 " const A();", |
| 690 " operator ==(other) => false;", |
| 691 "}", |
| 692 "class B {", |
| 693 " static const a = const A();", |
| 694 "}", |
| 695 "main() {", |
| 696 " const {B.a : 0};", |
| 697 "}")); |
| 698 resolve(source); |
| 699 assertErrors(source, CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPL
EMENTS_EQUALS); |
| 700 verify(source); |
| 701 } |
| 702 |
658 public void test_constMapKeyTypeImplementsEquals_super() throws Exception { | 703 public void test_constMapKeyTypeImplementsEquals_super() throws Exception { |
659 Source source = addSource(createSource(// | 704 Source source = addSource(createSource(// |
660 "class A {", | 705 "class A {", |
661 " const A();", | 706 " const A();", |
662 " operator ==(other) => false;", | 707 " operator ==(other) => false;", |
663 "}", | 708 "}", |
664 "class B extends A {", | 709 "class B extends A {", |
665 " const B();", | 710 " const B();", |
666 "}", | 711 "}", |
667 "main() {", | 712 "main() {", |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 " break;", | 1893 " break;", |
1849 " case 'a':", | 1894 " case 'a':", |
1850 " break;", | 1895 " break;", |
1851 " }", | 1896 " }", |
1852 "}")); | 1897 "}")); |
1853 resolve(source); | 1898 resolve(source); |
1854 assertErrors(source, CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES
); | 1899 assertErrors(source, CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES
); |
1855 verify(source); | 1900 verify(source); |
1856 } | 1901 } |
1857 | 1902 |
| 1903 public void test_inconsistentCaseExpressionTypes_dynamic() throws Exception { |
| 1904 // Even though A.S and S have a static type of "dynamic", we should see |
| 1905 // that they fail to match 3, because they are constant strings. |
| 1906 Source source = addSource(createSource(// |
| 1907 "class A {", |
| 1908 " static const S = 'A.S';", |
| 1909 "}", |
| 1910 "", |
| 1911 "const S = 'S';", |
| 1912 "", |
| 1913 "foo(var p) {", |
| 1914 " switch (p) {", |
| 1915 " case 3:", |
| 1916 " break;", |
| 1917 " case S:", |
| 1918 " break;", |
| 1919 " case A.S:", |
| 1920 " break;", |
| 1921 " }", |
| 1922 "}")); |
| 1923 resolve(source); |
| 1924 assertErrors( |
| 1925 source, |
| 1926 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
| 1927 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES); |
| 1928 verify(source); |
| 1929 } |
| 1930 |
1858 public void test_inconsistentCaseExpressionTypes_repeated() throws Exception { | 1931 public void test_inconsistentCaseExpressionTypes_repeated() throws Exception { |
1859 Source source = addSource(createSource(// | 1932 Source source = addSource(createSource(// |
1860 "f(var p) {", | 1933 "f(var p) {", |
1861 " switch (p) {", | 1934 " switch (p) {", |
1862 " case 1:", | 1935 " case 1:", |
1863 " break;", | 1936 " break;", |
1864 " case 'a':", | 1937 " case 'a':", |
1865 " break;", | 1938 " break;", |
1866 " case 'b':", | 1939 " case 'b':", |
1867 " break;", | 1940 " break;", |
(...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4313 assertErrors(source, CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPE
RATOR); | 4386 assertErrors(source, CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPE
RATOR); |
4314 verify(source); | 4387 verify(source); |
4315 reset(); | 4388 reset(); |
4316 } | 4389 } |
4317 | 4390 |
4318 private void check_wrongNumberOfParametersForOperator1(String name) throws Exc
eption { | 4391 private void check_wrongNumberOfParametersForOperator1(String name) throws Exc
eption { |
4319 check_wrongNumberOfParametersForOperator(name, ""); | 4392 check_wrongNumberOfParametersForOperator(name, ""); |
4320 check_wrongNumberOfParametersForOperator(name, "a, b"); | 4393 check_wrongNumberOfParametersForOperator(name, "a, b"); |
4321 } | 4394 } |
4322 } | 4395 } |
OLD | NEW |