Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1968063002: Handle more corner cases of closures while doing ast-based summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_ast_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 0, 1816 0,
1817 1, 1817 1,
1818 0, 1818 0,
1819 3 1819 3
1820 ], referenceValidators: [ 1820 ], referenceValidators: [
1821 (EntityRef r) => checkTypeRef(r, null, null, 'foo', 1821 (EntityRef r) => checkTypeRef(r, null, null, 'foo',
1822 expectedKind: ReferenceKind.topLevelFunction) 1822 expectedKind: ReferenceKind.topLevelFunction)
1823 ]); 1823 ]);
1824 } 1824 }
1825 1825
1826 test_constExpr_functionExpression_inConstructorInitializers() {
1827 // Even though function expressions are not allowed in constant
1828 // declarations, they might occur due to erroneous code, so make sure they
1829 // function correctly.
1830 UnlinkedExecutable executable = serializeClassText('''
1831 class C {
1832 final x, y;
1833 const C() : x = (() => 42), y = (() => 43);
1834 }
1835 ''').executables[0];
1836 expect(executable.localFunctions, hasLength(2));
1837 _assertUnlinkedConst(executable.constantInitializers[0].expression,
1838 isValidConst: false,
1839 operators: [UnlinkedConstOperation.pushLocalFunctionReference],
1840 ints: [0, 0]);
1841 _assertUnlinkedConst(executable.constantInitializers[1].expression,
1842 isValidConst: false,
1843 operators: [UnlinkedConstOperation.pushLocalFunctionReference],
1844 ints: [0, 1]);
1845 }
1846
1826 test_constExpr_invokeConstructor_generic_named() { 1847 test_constExpr_invokeConstructor_generic_named() {
1827 UnlinkedVariable variable = serializeVariableText(''' 1848 UnlinkedVariable variable = serializeVariableText('''
1828 class C<K, V> { 1849 class C<K, V> {
1829 const C.named(); 1850 const C.named();
1830 } 1851 }
1831 const v = const C<int, String>.named(); 1852 const v = const C<int, String>.named();
1832 '''); 1853 ''');
1833 _assertUnlinkedConst(variable.constExpr, operators: [ 1854 _assertUnlinkedConst(variable.constExpr, operators: [
1834 UnlinkedConstOperation.invokeConstructor, 1855 UnlinkedConstOperation.invokeConstructor,
1835 ], ints: [ 1856 ], ints: [
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 executable.constantInitializers[0]; 3485 executable.constantInitializers[0];
3465 expect( 3486 expect(
3466 initializer.kind, UnlinkedConstructorInitializerKind.superInvocation); 3487 initializer.kind, UnlinkedConstructorInitializerKind.superInvocation);
3467 expect(initializer.name, 'aaa'); 3488 expect(initializer.name, 'aaa');
3468 expect(initializer.expression, isNull); 3489 expect(initializer.expression, isNull);
3469 expect(initializer.arguments, hasLength(1)); 3490 expect(initializer.arguments, hasLength(1));
3470 _assertUnlinkedConst(initializer.arguments[0], 3491 _assertUnlinkedConst(initializer.arguments[0],
3471 operators: [UnlinkedConstOperation.pushInt], ints: [42]); 3492 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
3472 } 3493 }
3473 3494
3495 test_constructor_initializers_superInvocation_namedExpression() {
3496 UnlinkedExecutable executable =
3497 findExecutable('', executables: serializeClassText(r'''
3498 class A {
3499 const A(a, {int b, int c});
3500 }
3501 class C extends A {
3502 const C() : super(1, b: 2, c: 3);
3503 }
3504 ''').executables);
3505 expect(executable.constantInitializers, hasLength(1));
3506 UnlinkedConstructorInitializer initializer =
3507 executable.constantInitializers[0];
3508 expect(
3509 initializer.kind, UnlinkedConstructorInitializerKind.superInvocation);
3510 expect(initializer.name, '');
3511 expect(initializer.expression, isNull);
3512 expect(initializer.arguments, hasLength(3));
3513 _assertUnlinkedConst(initializer.arguments[0],
3514 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
3515 _assertUnlinkedConst(initializer.arguments[1],
3516 operators: [UnlinkedConstOperation.pushInt], ints: [2]);
3517 _assertUnlinkedConst(initializer.arguments[2],
3518 operators: [UnlinkedConstOperation.pushInt], ints: [3]);
3519 expect(initializer.argumentNames, ['b', 'c']);
3520 }
3521
3474 test_constructor_initializers_superInvocation_unnamed() { 3522 test_constructor_initializers_superInvocation_unnamed() {
3475 UnlinkedExecutable executable = 3523 UnlinkedExecutable executable =
3476 findExecutable('ccc', executables: serializeClassText(r''' 3524 findExecutable('ccc', executables: serializeClassText(r'''
3477 class A { 3525 class A {
3478 const A(int p); 3526 const A(int p);
3479 } 3527 }
3480 class C extends A { 3528 class C extends A {
3481 const C.ccc() : super(42); 3529 const C.ccc() : super(42);
3482 } 3530 }
3483 ''').executables); 3531 ''').executables);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 expect(initializer.arguments, hasLength(3)); 3579 expect(initializer.arguments, hasLength(3));
3532 _assertUnlinkedConst(initializer.arguments[0], 3580 _assertUnlinkedConst(initializer.arguments[0],
3533 operators: [UnlinkedConstOperation.pushInt], ints: [1]); 3581 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
3534 _assertUnlinkedConst(initializer.arguments[1], 3582 _assertUnlinkedConst(initializer.arguments[1],
3535 operators: [UnlinkedConstOperation.pushInt], ints: [2]); 3583 operators: [UnlinkedConstOperation.pushInt], ints: [2]);
3536 _assertUnlinkedConst(initializer.arguments[2], 3584 _assertUnlinkedConst(initializer.arguments[2],
3537 operators: [UnlinkedConstOperation.pushInt], ints: [3]); 3585 operators: [UnlinkedConstOperation.pushInt], ints: [3]);
3538 expect(initializer.argumentNames, ['b', 'c']); 3586 expect(initializer.argumentNames, ['b', 'c']);
3539 } 3587 }
3540 3588
3541 test_constructor_initializers_superInvocation_namedExpression() {
3542 UnlinkedExecutable executable =
3543 findExecutable('', executables: serializeClassText(r'''
3544 class A {
3545 const A(a, {int b, int c});
3546 }
3547 class C extends A {
3548 const C() : super(1, b: 2, c: 3);
3549 }
3550 ''').executables);
3551 expect(executable.constantInitializers, hasLength(1));
3552 UnlinkedConstructorInitializer initializer =
3553 executable.constantInitializers[0];
3554 expect(
3555 initializer.kind, UnlinkedConstructorInitializerKind.superInvocation);
3556 expect(initializer.name, '');
3557 expect(initializer.expression, isNull);
3558 expect(initializer.arguments, hasLength(3));
3559 _assertUnlinkedConst(initializer.arguments[0],
3560 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
3561 _assertUnlinkedConst(initializer.arguments[1],
3562 operators: [UnlinkedConstOperation.pushInt], ints: [2]);
3563 _assertUnlinkedConst(initializer.arguments[2],
3564 operators: [UnlinkedConstOperation.pushInt], ints: [3]);
3565 expect(initializer.argumentNames, ['b', 'c']);
3566 }
3567
3568 test_constructor_initializers_thisInvocation_unnamed() { 3589 test_constructor_initializers_thisInvocation_unnamed() {
3569 UnlinkedExecutable executable = 3590 UnlinkedExecutable executable =
3570 findExecutable('named', executables: serializeClassText(r''' 3591 findExecutable('named', executables: serializeClassText(r'''
3571 class C { 3592 class C {
3572 const C.named() : this(1, 'bbb'); 3593 const C.named() : this(1, 'bbb');
3573 const C(int a, String b); 3594 const C(int a, String b);
3574 } 3595 }
3575 ''').executables); 3596 ''').executables);
3576 expect(executable.constantInitializers, hasLength(1)); 3597 expect(executable.constantInitializers, hasLength(1));
3577 UnlinkedConstructorInitializer initializer = 3598 UnlinkedConstructorInitializer initializer =
(...skipping 6520 matching lines...) Expand 10 before | Expand all | Expand 10 after
10098 class _PrefixExpectation { 10119 class _PrefixExpectation {
10099 final ReferenceKind kind; 10120 final ReferenceKind kind;
10100 final String name; 10121 final String name;
10101 final String absoluteUri; 10122 final String absoluteUri;
10102 final String relativeUri; 10123 final String relativeUri;
10103 final int numTypeParameters; 10124 final int numTypeParameters;
10104 10125
10105 _PrefixExpectation(this.kind, this.name, 10126 _PrefixExpectation(this.kind, this.name,
10106 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 10127 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
10107 } 10128 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_ast_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698