| 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 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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 | 1749 |
| 1750 test_constExpr_constructorParam_shadows_classMember() { | 1750 test_constExpr_constructorParam_shadows_classMember() { |
| 1751 UnlinkedClass cls = serializeClassText(''' | 1751 UnlinkedClass cls = serializeClassText(''' |
| 1752 class C { | 1752 class C { |
| 1753 static const a = null; | 1753 static const a = null; |
| 1754 final b; | 1754 final b; |
| 1755 const C(a) : b = a; | 1755 const C(a) : b = a; |
| 1756 } | 1756 } |
| 1757 '''); | 1757 '''); |
| 1758 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression, | 1758 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression, |
| 1759 operators: [UnlinkedConstOperation.pushConstructorParameter], | 1759 operators: [UnlinkedConstOperation.pushParameter], strings: ['a']); |
| 1760 strings: ['a']); | |
| 1761 } | 1760 } |
| 1762 | 1761 |
| 1763 test_constExpr_constructorParam_shadows_typeParam() { | 1762 test_constExpr_constructorParam_shadows_typeParam() { |
| 1764 UnlinkedClass cls = serializeClassText(''' | 1763 UnlinkedClass cls = serializeClassText(''' |
| 1765 class C<T> { | 1764 class C<T> { |
| 1766 final x; | 1765 final x; |
| 1767 const C(T) : x = T; | 1766 const C(T) : x = T; |
| 1768 } | 1767 } |
| 1769 '''); | 1768 '''); |
| 1770 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression, | 1769 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression, |
| 1771 operators: [UnlinkedConstOperation.pushConstructorParameter], | 1770 operators: [UnlinkedConstOperation.pushParameter], strings: ['T']); |
| 1772 strings: ['T']); | |
| 1773 } | 1771 } |
| 1774 | 1772 |
| 1775 test_constExpr_functionExpression_asArgument() { | 1773 test_constExpr_functionExpression_asArgument() { |
| 1776 // Even though function expressions are not allowed in constant | 1774 // Even though function expressions are not allowed in constant |
| 1777 // declarations, they might occur due to erroneous code, so make sure they | 1775 // declarations, they might occur due to erroneous code, so make sure they |
| 1778 // function correctly. | 1776 // function correctly. |
| 1779 UnlinkedVariable variable = serializeVariableText(''' | 1777 UnlinkedVariable variable = serializeVariableText(''' |
| 1780 const v = foo(5, () => 42); | 1778 const v = foo(5, () => 42); |
| 1781 foo(a, b) {} | 1779 foo(a, b) {} |
| 1782 '''); | 1780 '''); |
| (...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3455 final x; | 3453 final x; |
| 3456 const C(int p) : x = p; | 3454 const C(int p) : x = p; |
| 3457 } | 3455 } |
| 3458 ''').executables); | 3456 ''').executables); |
| 3459 expect(executable.constantInitializers, hasLength(1)); | 3457 expect(executable.constantInitializers, hasLength(1)); |
| 3460 UnlinkedConstructorInitializer initializer = | 3458 UnlinkedConstructorInitializer initializer = |
| 3461 executable.constantInitializers[0]; | 3459 executable.constantInitializers[0]; |
| 3462 expect(initializer.kind, UnlinkedConstructorInitializerKind.field); | 3460 expect(initializer.kind, UnlinkedConstructorInitializerKind.field); |
| 3463 expect(initializer.name, 'x'); | 3461 expect(initializer.name, 'x'); |
| 3464 _assertUnlinkedConst(initializer.expression, | 3462 _assertUnlinkedConst(initializer.expression, |
| 3465 operators: [UnlinkedConstOperation.pushConstructorParameter], | 3463 operators: [UnlinkedConstOperation.pushParameter], strings: ['p']); |
| 3466 strings: ['p']); | |
| 3467 expect(initializer.arguments, isEmpty); | 3464 expect(initializer.arguments, isEmpty); |
| 3468 } | 3465 } |
| 3469 | 3466 |
| 3470 test_constructor_initializers_notConst() { | 3467 test_constructor_initializers_notConst() { |
| 3471 UnlinkedExecutable executable = | 3468 UnlinkedExecutable executable = |
| 3472 findExecutable('', executables: serializeClassText(r''' | 3469 findExecutable('', executables: serializeClassText(r''' |
| 3473 class C { | 3470 class C { |
| 3474 final x; | 3471 final x; |
| 3475 C() : x = 42; | 3472 C() : x = 42; |
| 3476 } | 3473 } |
| (...skipping 3599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7076 operators: [UnlinkedConstOperation.pushInt], ints: [1]); | 7073 operators: [UnlinkedConstOperation.pushInt], ints: [1]); |
| 7077 } | 7074 } |
| 7078 | 7075 |
| 7079 test_expr_inClosure_noTypeInferenceNeeded() { | 7076 test_expr_inClosure_noTypeInferenceNeeded() { |
| 7080 // We don't serialize closure body expressions for closures that don't need | 7077 // We don't serialize closure body expressions for closures that don't need |
| 7081 // to participate in type inference. | 7078 // to participate in type inference. |
| 7082 UnlinkedVariable variable = serializeVariableText('Object v = () => 1;'); | 7079 UnlinkedVariable variable = serializeVariableText('Object v = () => 1;'); |
| 7083 expect(variable.initializer.localFunctions[0].bodyExpr, isNull); | 7080 expect(variable.initializer.localFunctions[0].bodyExpr, isNull); |
| 7084 } | 7081 } |
| 7085 | 7082 |
| 7083 test_expr_inClosure_refersToOuterParam() { |
| 7084 if (skipNonConstInitializers) { |
| 7085 return; |
| 7086 } |
| 7087 UnlinkedVariable variable = |
| 7088 serializeVariableText('var v = (x) => (y) => x;'); |
| 7089 _assertUnlinkedConst( |
| 7090 variable.initializer.localFunctions[0].localFunctions[0].bodyExpr, |
| 7091 operators: [UnlinkedConstOperation.pushParameter], |
| 7092 strings: ['x']); |
| 7093 } |
| 7094 |
| 7095 test_expr_inClosure_refersToParam() { |
| 7096 if (skipNonConstInitializers) { |
| 7097 return; |
| 7098 } |
| 7099 UnlinkedVariable variable = serializeVariableText('var v = (x) => x;'); |
| 7100 _assertUnlinkedConst(variable.initializer.localFunctions[0].bodyExpr, |
| 7101 operators: [UnlinkedConstOperation.pushParameter], strings: ['x']); |
| 7102 } |
| 7103 |
| 7104 test_expr_inClosure_refersToParam_outOfScope() { |
| 7105 if (skipNonConstInitializers) { |
| 7106 return; |
| 7107 } |
| 7108 UnlinkedVariable variable = |
| 7109 serializeVariableText('var x; var v = (b) => (b ? (x) => x : x);'); |
| 7110 _assertUnlinkedConst(variable.initializer.localFunctions[0].bodyExpr, |
| 7111 isValidConst: false, |
| 7112 operators: [ |
| 7113 UnlinkedConstOperation.pushParameter, |
| 7114 UnlinkedConstOperation.pushLocalFunctionReference, |
| 7115 UnlinkedConstOperation.pushReference, |
| 7116 UnlinkedConstOperation.conditional, |
| 7117 ], |
| 7118 strings: [ |
| 7119 'b' |
| 7120 ], |
| 7121 ints: [ |
| 7122 0, |
| 7123 0 |
| 7124 ], |
| 7125 referenceValidators: [ |
| 7126 (EntityRef r) => checkTypeRef(r, null, null, 'x', |
| 7127 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 7128 ]); |
| 7129 } |
| 7130 |
| 7086 test_expr_invokeMethod_instance() { | 7131 test_expr_invokeMethod_instance() { |
| 7087 if (skipNonConstInitializers) { | 7132 if (skipNonConstInitializers) { |
| 7088 return; | 7133 return; |
| 7089 } | 7134 } |
| 7090 UnlinkedVariable variable = serializeVariableText(''' | 7135 UnlinkedVariable variable = serializeVariableText(''' |
| 7091 class C { | 7136 class C { |
| 7092 int m(a, {b, c}) => 42; | 7137 int m(a, {b, c}) => 42; |
| 7093 } | 7138 } |
| 7094 final v = new C().m(1, b: 2, c: 3); | 7139 final v = new C().m(1, b: 2, c: 3); |
| 7095 '''); | 7140 '''); |
| (...skipping 3188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10284 class _PrefixExpectation { | 10329 class _PrefixExpectation { |
| 10285 final ReferenceKind kind; | 10330 final ReferenceKind kind; |
| 10286 final String name; | 10331 final String name; |
| 10287 final String absoluteUri; | 10332 final String absoluteUri; |
| 10288 final String relativeUri; | 10333 final String relativeUri; |
| 10289 final int numTypeParameters; | 10334 final int numTypeParameters; |
| 10290 | 10335 |
| 10291 _PrefixExpectation(this.kind, this.name, | 10336 _PrefixExpectation(this.kind, this.name, |
| 10292 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 10337 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 10293 } | 10338 } |
| OLD | NEW |