OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart2js.semantics_visitor_test; | 5 part of dart2js.semantics_visitor_test; |
6 | 6 |
7 const Map<String, List<Test>> SEND_TESTS = const { | 7 const Map<String, List<Test>> SEND_TESTS = const { |
8 'Parameters': const [ | 8 'Parameters': const [ |
9 // Parameters | 9 // Parameters |
10 const Test('m(o) => o;', | 10 const Test('m(o) => o;', |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 ''' | 299 ''' |
300 class C { static get o => 42; } | 300 class C { static get o => 42; } |
301 m() { C.o = 42; } | 301 m() { C.o = 42; } |
302 ''', | 302 ''', |
303 const Visit(VisitKind.VISIT_UNRESOLVED_SET, | 303 const Visit(VisitKind.VISIT_UNRESOLVED_SET, |
304 name: 'o', | 304 name: 'o', |
305 rhs: '42')), | 305 rhs: '42')), |
306 const Test.clazz( | 306 const Test.clazz( |
307 ''' | 307 ''' |
308 class C { | 308 class C { |
309 static static get o => 42; | 309 static get o => 42; |
310 m() { o = 42; } | 310 m() { o = 42; } |
311 } | 311 } |
312 ''', | 312 ''', |
313 const Visit(VisitKind.VISIT_UNRESOLVED_SET, | 313 const Visit(VisitKind.VISIT_UNRESOLVED_SET, |
314 name: 'o', | 314 name: 'o', |
315 rhs: '42')), | 315 rhs: '42')), |
316 const Test.clazz( | 316 const Test.clazz( |
317 ''' | 317 ''' |
318 class C { | 318 class C { |
319 static static get o => 42; | 319 static get o => 42; |
320 m() { C.o = 42; } | 320 m() { C.o = 42; } |
321 } | 321 } |
322 ''', | 322 ''', |
323 const Visit(VisitKind.VISIT_UNRESOLVED_SET, | 323 const Visit(VisitKind.VISIT_UNRESOLVED_SET, |
324 name: 'o', | 324 name: 'o', |
325 rhs: '42')), | 325 rhs: '42')), |
326 const Test.prefix( | 326 const Test.prefix( |
327 ''' | 327 ''' |
328 class C { | 328 class C { |
329 static static get o => 42; | 329 static get o => 42; |
330 } | 330 } |
331 ''', | 331 ''', |
332 'm() { p.C.o = 42; }', | 332 'm() { p.C.o = 42; }', |
333 const Visit(VisitKind.VISIT_UNRESOLVED_SET, | 333 const Visit(VisitKind.VISIT_UNRESOLVED_SET, |
334 name: 'o', | 334 name: 'o', |
335 rhs: '42')), | 335 rhs: '42')), |
336 // TODO(johnniwinther): Expected [VISIT_STATIC_SETTER_GET] instead. | 336 // TODO(johnniwinther): Expected [VISIT_STATIC_SETTER_GET] instead. |
337 const Test( | 337 const Test( |
338 ''' | 338 ''' |
339 class C { | 339 class C { |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 constant: 'Type', | 1375 constant: 'Type', |
1376 operator: '--')), | 1376 operator: '--')), |
1377 ], | 1377 ], |
1378 'Assert': const [ | 1378 'Assert': const [ |
1379 // Assert | 1379 // Assert |
1380 const Test( | 1380 const Test( |
1381 ''' | 1381 ''' |
1382 m() { assert(false); } | 1382 m() { assert(false); } |
1383 ''', | 1383 ''', |
1384 const Visit(VisitKind.VISIT_ASSERT, expression: 'false')), | 1384 const Visit(VisitKind.VISIT_ASSERT, expression: 'false')), |
| 1385 const Test( |
| 1386 ''' |
| 1387 m() { assert(); } |
| 1388 ''', |
| 1389 const Visit(VisitKind.ERROR_INVALID_ASSERT, arguments: '()')), |
| 1390 const Test( |
| 1391 ''' |
| 1392 m() { assert(42, true); } |
| 1393 ''', |
| 1394 const Visit(VisitKind.ERROR_INVALID_ASSERT, arguments: '(42,true)')), |
1385 ], | 1395 ], |
1386 'Logical and': const [ | 1396 'Logical and': const [ |
1387 // Logical and | 1397 // Logical and |
1388 const Test( | 1398 const Test( |
1389 ''' | 1399 ''' |
1390 m() => true && false; | 1400 m() => true && false; |
1391 ''', | 1401 ''', |
1392 const Visit(VisitKind.VISIT_LOGICAL_AND, left: 'true', right: 'false')), | 1402 const Visit(VisitKind.VISIT_LOGICAL_AND, left: 'true', right: 'false')), |
1393 ], | 1403 ], |
1394 'Logical or': const [ | 1404 'Logical or': const [ |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 const Test.clazz( | 1544 const Test.clazz( |
1535 ''' | 1545 ''' |
1536 class B {} | 1546 class B {} |
1537 class C extends B { | 1547 class C extends B { |
1538 m() => super + 42; | 1548 m() => super + 42; |
1539 } | 1549 } |
1540 ''', | 1550 ''', |
1541 const Visit(VisitKind.VISIT_UNRESOLVED_SUPER_BINARY, | 1551 const Visit(VisitKind.VISIT_UNRESOLVED_SUPER_BINARY, |
1542 operator: '+', | 1552 operator: '+', |
1543 right: '42')), | 1553 right: '42')), |
| 1554 const Test( |
| 1555 ''' |
| 1556 m() => 2 === 3; |
| 1557 ''', |
| 1558 const Visit(VisitKind.ERROR_UNDEFINED_BINARY_EXPRESSION, |
| 1559 left: '2', operator: '===', right: '3')), |
| 1560 const Test( |
| 1561 ''' |
| 1562 m() => 2 !== 3; |
| 1563 ''', |
| 1564 const Visit(VisitKind.ERROR_UNDEFINED_BINARY_EXPRESSION, |
| 1565 left: '2', operator: '!==', right: '3')), |
1544 ], | 1566 ], |
1545 'Index': const [ | 1567 'Index': const [ |
1546 // Index | 1568 // Index |
1547 const Test( | 1569 const Test( |
1548 ''' | 1570 ''' |
1549 m() => 2[3]; | 1571 m() => 2[3]; |
1550 ''', | 1572 ''', |
1551 const Visit(VisitKind.VISIT_INDEX, | 1573 const Visit(VisitKind.VISIT_INDEX, |
1552 receiver: '2', index: '3')), | 1574 receiver: '2', index: '3')), |
1553 const Test( | 1575 const Test( |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 m() => ~super; | 1797 m() => ~super; |
1776 } | 1798 } |
1777 ''', | 1799 ''', |
1778 const Visit(VisitKind.VISIT_SUPER_UNARY, | 1800 const Visit(VisitKind.VISIT_SUPER_UNARY, |
1779 element: 'function(B#~)', operator: '~')), | 1801 element: 'function(B#~)', operator: '~')), |
1780 const Test( | 1802 const Test( |
1781 ''' | 1803 ''' |
1782 m() => !0; | 1804 m() => !0; |
1783 ''', | 1805 ''', |
1784 const Visit(VisitKind.VISIT_NOT, expression: '0')), | 1806 const Visit(VisitKind.VISIT_NOT, expression: '0')), |
| 1807 const Test( |
| 1808 ''' |
| 1809 m() => +false; |
| 1810 ''', |
| 1811 // TODO(johnniwinther): Should this be an |
| 1812 // ERROR_UNDEFINED_UNARY_EXPRESSION? Currently the parser just skips |
| 1813 // the `+`. |
| 1814 const []), |
1785 ], | 1815 ], |
1786 'Index set': const [ | 1816 'Index set': const [ |
1787 // Index set | 1817 // Index set |
1788 const Test( | 1818 const Test( |
1789 ''' | 1819 ''' |
1790 m() => 0[1] = 2; | 1820 m() => 0[1] = 2; |
1791 ''', | 1821 ''', |
1792 const Visit(VisitKind.VISIT_INDEX_SET, | 1822 const Visit(VisitKind.VISIT_INDEX_SET, |
1793 receiver: '0', index: '1', rhs: '2')), | 1823 receiver: '0', index: '1', rhs: '2')), |
1794 const Test.clazz( | 1824 const Test.clazz( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 m() { | 1874 m() { |
1845 var a; | 1875 var a; |
1846 a += 42; | 1876 a += 42; |
1847 } | 1877 } |
1848 ''', | 1878 ''', |
1849 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_COMPOUND, | 1879 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_COMPOUND, |
1850 element: 'variable(m#a)', operator: '+=', rhs: '42')), | 1880 element: 'variable(m#a)', operator: '+=', rhs: '42')), |
1851 const Test( | 1881 const Test( |
1852 ''' | 1882 ''' |
1853 m() { | 1883 m() { |
1854 final a; | 1884 final a = 0; |
1855 a += 42; | 1885 a += 42; |
1856 } | 1886 } |
1857 ''', | 1887 ''', |
1858 const Visit(VisitKind.VISIT_FINAL_LOCAL_VARIABLE_COMPOUND, | 1888 const Visit(VisitKind.VISIT_FINAL_LOCAL_VARIABLE_COMPOUND, |
1859 element: 'variable(m#a)', operator: '+=', rhs: '42')), | 1889 element: 'variable(m#a)', operator: '+=', rhs: '42')), |
1860 const Test( | 1890 const Test( |
1861 ''' | 1891 ''' |
1862 m() { | 1892 m() { |
1863 a() {} | 1893 a() {} |
1864 a += 42; | 1894 a += 42; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 const Visit(VisitKind.VISIT_SUPER_FIELD_SETTER_COMPOUND, | 2148 const Visit(VisitKind.VISIT_SUPER_FIELD_SETTER_COMPOUND, |
2119 getter: 'field(A#a)', setter: 'setter(B#a)', | 2149 getter: 'field(A#a)', setter: 'setter(B#a)', |
2120 operator: '+=', rhs: '42')), | 2150 operator: '+=', rhs: '42')), |
2121 // TODO(johnniwinther): Enable this when dart2js supports shadow setters. | 2151 // TODO(johnniwinther): Enable this when dart2js supports shadow setters. |
2122 /*const Test.clazz( | 2152 /*const Test.clazz( |
2123 ''' | 2153 ''' |
2124 class A { | 2154 class A { |
2125 var a; | 2155 var a; |
2126 } | 2156 } |
2127 class B extends A { | 2157 class B extends A { |
2128 final a; | 2158 final a = 0; |
2129 } | 2159 } |
2130 | 2160 |
2131 class C extends B { | 2161 class C extends B { |
2132 m() => super.a += 42; | 2162 m() => super.a += 42; |
2133 } | 2163 } |
2134 ''', | 2164 ''', |
2135 const Visit(VisitKind.VISIT_SUPER_FIELD_FIELD_COMPOUND, | 2165 const Visit(VisitKind.VISIT_SUPER_FIELD_FIELD_COMPOUND, |
2136 getter: 'field(B#a)', setter: 'field(A#a)', | 2166 getter: 'field(B#a)', setter: 'field(A#a)', |
2137 operator: '+=', rhs: '42')),*/ | 2167 operator: '+=', rhs: '42')),*/ |
2138 const Test.clazz( | 2168 const Test.clazz( |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3360 } | 3390 } |
3361 m() => new Class(true, 42); | 3391 m() => new Class(true, 42); |
3362 ''', | 3392 ''', |
3363 const Visit( | 3393 const Visit( |
3364 VisitKind.VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, | 3394 VisitKind.VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, |
3365 element: 'function(Class#)', | 3395 element: 'function(Class#)', |
3366 arguments: '(true,42)', | 3396 arguments: '(true,42)', |
3367 type: 'Class', | 3397 type: 'Class', |
3368 selector: 'CallStructure(arity=2)')), | 3398 selector: 'CallStructure(arity=2)')), |
3369 ], | 3399 ], |
| 3400 'If not null expressions': const [ |
| 3401 const Test( |
| 3402 ''' |
| 3403 m(a) => a?.b; |
| 3404 ''', |
| 3405 const [ |
| 3406 const Visit( |
| 3407 VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_GET, |
| 3408 receiver: 'a', |
| 3409 name: 'b'), |
| 3410 const Visit( |
| 3411 VisitKind.VISIT_PARAMETER_GET, |
| 3412 element: 'parameter(m#a)'), |
| 3413 ]), |
| 3414 const Test( |
| 3415 ''' |
| 3416 m(a) => a?.b = 42; |
| 3417 ''', |
| 3418 const [ |
| 3419 const Visit( |
| 3420 VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_SET, |
| 3421 receiver: 'a', |
| 3422 name: 'b', |
| 3423 rhs: '42'), |
| 3424 const Visit( |
| 3425 VisitKind.VISIT_PARAMETER_GET, |
| 3426 element: 'parameter(m#a)'), |
| 3427 ]), |
| 3428 const Test( |
| 3429 ''' |
| 3430 m(a) => a?.b(42, true); |
| 3431 ''', |
| 3432 const [ |
| 3433 const Visit( |
| 3434 VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_INVOKE, |
| 3435 receiver: 'a', |
| 3436 arguments: '(42,true)', |
| 3437 selector: 'Selector(call, b, arity=2)'), |
| 3438 const Visit( |
| 3439 VisitKind.VISIT_PARAMETER_GET, |
| 3440 element: 'parameter(m#a)'), |
| 3441 ]), |
| 3442 const Test( |
| 3443 ''' |
| 3444 m(a) => ++a?.b; |
| 3445 ''', |
| 3446 const [ |
| 3447 const Visit( |
| 3448 VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_PREFIX, |
| 3449 receiver: 'a', |
| 3450 getter: 'Selector(getter, b, arity=0)', |
| 3451 setter: 'Selector(setter, b, arity=1)', |
| 3452 operator: '++'), |
| 3453 const Visit( |
| 3454 VisitKind.VISIT_PARAMETER_GET, |
| 3455 element: 'parameter(m#a)'), |
| 3456 ]), |
| 3457 const Test( |
| 3458 ''' |
| 3459 m(a) => a?.b--; |
| 3460 ''', |
| 3461 const [ |
| 3462 const Visit( |
| 3463 VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_POSTFIX, |
| 3464 receiver: 'a', |
| 3465 getter: 'Selector(getter, b, arity=0)', |
| 3466 setter: 'Selector(setter, b, arity=1)', |
| 3467 operator: '--'), |
| 3468 const Visit( |
| 3469 VisitKind.VISIT_PARAMETER_GET, |
| 3470 element: 'parameter(m#a)'), |
| 3471 ]), |
| 3472 const Test( |
| 3473 ''' |
| 3474 m(a) => a?.b *= 42; |
| 3475 ''', |
| 3476 const [ |
| 3477 const Visit( |
| 3478 VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_COMPOUND, |
| 3479 receiver: 'a', |
| 3480 getter: 'Selector(getter, b, arity=0)', |
| 3481 setter: 'Selector(setter, b, arity=1)', |
| 3482 operator: '*=', |
| 3483 rhs: '42'), |
| 3484 const Visit( |
| 3485 VisitKind.VISIT_PARAMETER_GET, |
| 3486 element: 'parameter(m#a)'), |
| 3487 ]), |
| 3488 const Test( |
| 3489 ''' |
| 3490 m(a, b) => a ?? b; |
| 3491 ''', |
| 3492 const [ |
| 3493 const Visit(VisitKind.VISIT_IF_NULL, |
| 3494 left: 'a', right: 'b'), |
| 3495 const Visit( |
| 3496 VisitKind.VISIT_PARAMETER_GET, |
| 3497 element: 'parameter(m#a)'), |
| 3498 const Visit( |
| 3499 VisitKind.VISIT_PARAMETER_GET, |
| 3500 element: 'parameter(m#b)'), |
| 3501 ]), |
| 3502 const Test( |
| 3503 ''' |
| 3504 m(a) => a ??= 42; |
| 3505 ''', |
| 3506 const Visit( |
| 3507 VisitKind.VISIT_PARAMETER_COMPOUND, |
| 3508 element: 'parameter(m#a)', |
| 3509 operator: '??=', |
| 3510 rhs: '42')), |
| 3511 ], |
3370 }; | 3512 }; |
OLD | NEW |