| 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 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 class C<T> { | 1765 class C<T> { |
| 1766 final x; | 1766 final x; |
| 1767 const C(T) : x = T; | 1767 const C(T) : x = T; |
| 1768 } | 1768 } |
| 1769 '''); | 1769 '''); |
| 1770 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression, | 1770 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression, |
| 1771 operators: [UnlinkedConstOperation.pushConstructorParameter], | 1771 operators: [UnlinkedConstOperation.pushConstructorParameter], |
| 1772 strings: ['T']); | 1772 strings: ['T']); |
| 1773 } | 1773 } |
| 1774 | 1774 |
| 1775 test_constExpr_functionExpression_asArgument() { |
| 1776 // Even though function expressions are not allowed in constant |
| 1777 // declarations, they might occur due to erroneous code, so make sure they |
| 1778 // function correctly. |
| 1779 UnlinkedVariable variable = serializeVariableText(''' |
| 1780 const v = foo(5, () => 42); |
| 1781 foo(a, b) {} |
| 1782 '''); |
| 1783 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 1784 UnlinkedConstOperation.pushInt, |
| 1785 UnlinkedConstOperation.pushLocalFunctionReference, |
| 1786 UnlinkedConstOperation.invokeMethodRef |
| 1787 ], ints: [ |
| 1788 5, |
| 1789 0, |
| 1790 0, |
| 1791 0, |
| 1792 2 |
| 1793 ], referenceValidators: [ |
| 1794 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 1795 expectedKind: ReferenceKind.topLevelFunction) |
| 1796 ]); |
| 1797 } |
| 1798 |
| 1799 test_constExpr_functionExpression_asArgument_multiple() { |
| 1800 // Even though function expressions are not allowed in constant |
| 1801 // declarations, they might occur due to erroneous code, so make sure they |
| 1802 // function correctly. |
| 1803 UnlinkedVariable variable = serializeVariableText(''' |
| 1804 const v = foo(5, () => 42, () => 43); |
| 1805 foo(a, b, c) {} |
| 1806 '''); |
| 1807 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 1808 UnlinkedConstOperation.pushInt, |
| 1809 UnlinkedConstOperation.pushLocalFunctionReference, |
| 1810 UnlinkedConstOperation.pushLocalFunctionReference, |
| 1811 UnlinkedConstOperation.invokeMethodRef |
| 1812 ], ints: [ |
| 1813 5, |
| 1814 0, |
| 1815 0, |
| 1816 0, |
| 1817 1, |
| 1818 0, |
| 1819 3 |
| 1820 ], referenceValidators: [ |
| 1821 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 1822 expectedKind: ReferenceKind.topLevelFunction) |
| 1823 ]); |
| 1824 } |
| 1825 |
| 1775 test_constExpr_invokeConstructor_generic_named() { | 1826 test_constExpr_invokeConstructor_generic_named() { |
| 1776 UnlinkedVariable variable = serializeVariableText(''' | 1827 UnlinkedVariable variable = serializeVariableText(''' |
| 1777 class C<K, V> { | 1828 class C<K, V> { |
| 1778 const C.named(); | 1829 const C.named(); |
| 1779 } | 1830 } |
| 1780 const v = const C<int, String>.named(); | 1831 const v = const C<int, String>.named(); |
| 1781 '''); | 1832 '''); |
| 1782 _assertUnlinkedConst(variable.constExpr, operators: [ | 1833 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1783 UnlinkedConstOperation.invokeConstructor, | 1834 UnlinkedConstOperation.invokeConstructor, |
| 1784 ], ints: [ | 1835 ], ints: [ |
| (...skipping 5012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6797 test_expr_functionExpression_asArgument() { | 6848 test_expr_functionExpression_asArgument() { |
| 6798 if (skipNonConstInitializers) { | 6849 if (skipNonConstInitializers) { |
| 6799 return; | 6850 return; |
| 6800 } | 6851 } |
| 6801 UnlinkedVariable variable = serializeVariableText(''' | 6852 UnlinkedVariable variable = serializeVariableText(''' |
| 6802 final v = foo(5, () => 42); | 6853 final v = foo(5, () => 42); |
| 6803 foo(a, b) {} | 6854 foo(a, b) {} |
| 6804 '''); | 6855 '''); |
| 6805 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ | 6856 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6806 UnlinkedConstOperation.pushInt, | 6857 UnlinkedConstOperation.pushInt, |
| 6807 UnlinkedConstOperation.pushNull, | 6858 UnlinkedConstOperation.pushLocalFunctionReference, |
| 6808 UnlinkedConstOperation.invokeMethodRef | 6859 UnlinkedConstOperation.invokeMethodRef |
| 6809 ], ints: [ | 6860 ], ints: [ |
| 6810 5, | 6861 5, |
| 6811 0, | 6862 0, |
| 6863 0, |
| 6864 0, |
| 6812 2 | 6865 2 |
| 6813 ], referenceValidators: [ | 6866 ], referenceValidators: [ |
| 6814 (EntityRef r) => checkTypeRef(r, null, null, 'foo', | 6867 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 6815 expectedKind: ReferenceKind.topLevelFunction) | 6868 expectedKind: ReferenceKind.topLevelFunction) |
| 6816 ]); | 6869 ]); |
| 6817 } | 6870 } |
| 6818 | 6871 |
| 6872 test_expr_functionExpression_asArgument_multiple() { |
| 6873 if (skipNonConstInitializers) { |
| 6874 return; |
| 6875 } |
| 6876 UnlinkedVariable variable = serializeVariableText(''' |
| 6877 final v = foo(5, () => 42, () => 43); |
| 6878 foo(a, b, c) {} |
| 6879 '''); |
| 6880 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6881 UnlinkedConstOperation.pushInt, |
| 6882 UnlinkedConstOperation.pushLocalFunctionReference, |
| 6883 UnlinkedConstOperation.pushLocalFunctionReference, |
| 6884 UnlinkedConstOperation.invokeMethodRef |
| 6885 ], ints: [ |
| 6886 5, |
| 6887 0, |
| 6888 0, |
| 6889 0, |
| 6890 1, |
| 6891 0, |
| 6892 3 |
| 6893 ], referenceValidators: [ |
| 6894 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 6895 expectedKind: ReferenceKind.topLevelFunction) |
| 6896 ]); |
| 6897 } |
| 6898 |
| 6819 test_expr_functionExpression_withBlockBody() { | 6899 test_expr_functionExpression_withBlockBody() { |
| 6820 if (skipNonConstInitializers) { | 6900 if (skipNonConstInitializers) { |
| 6821 return; | 6901 return; |
| 6822 } | 6902 } |
| 6823 UnlinkedVariable variable = serializeVariableText(''' | 6903 UnlinkedVariable variable = serializeVariableText(''' |
| 6824 final v = () { return 42; }; | 6904 final v = () { return 42; }; |
| 6825 '''); | 6905 '''); |
| 6826 _assertUnlinkedConst(variable.constExpr, | 6906 _assertUnlinkedConst(variable.constExpr, |
| 6827 isValidConst: false, operators: [UnlinkedConstOperation.pushNull]); | 6907 isValidConst: false, |
| 6908 operators: [UnlinkedConstOperation.pushLocalFunctionReference], |
| 6909 ints: [0, 0]); |
| 6828 } | 6910 } |
| 6829 | 6911 |
| 6830 test_expr_functionExpression_withExpressionBody() { | 6912 test_expr_functionExpression_withExpressionBody() { |
| 6831 if (skipNonConstInitializers) { | 6913 if (skipNonConstInitializers) { |
| 6832 return; | 6914 return; |
| 6833 } | 6915 } |
| 6834 UnlinkedVariable variable = serializeVariableText(''' | 6916 UnlinkedVariable variable = serializeVariableText(''' |
| 6835 final v = () => 42; | 6917 final v = () => 42; |
| 6836 '''); | 6918 '''); |
| 6837 _assertUnlinkedConst(variable.constExpr, | 6919 _assertUnlinkedConst(variable.constExpr, |
| 6838 isValidConst: false, operators: [UnlinkedConstOperation.pushNull]); | 6920 isValidConst: false, |
| 6921 operators: [UnlinkedConstOperation.pushLocalFunctionReference], |
| 6922 ints: [0, 0]); |
| 6839 } | 6923 } |
| 6840 | 6924 |
| 6841 test_expr_functionExpressionInvocation_withBlockBody() { | 6925 test_expr_functionExpressionInvocation_withBlockBody() { |
| 6842 if (skipNonConstInitializers) { | 6926 if (skipNonConstInitializers) { |
| 6843 return; | 6927 return; |
| 6844 } | 6928 } |
| 6845 UnlinkedVariable variable = serializeVariableText(''' | 6929 UnlinkedVariable variable = serializeVariableText(''' |
| 6846 final v = ((a, b) {return 42;})(1, 2); | 6930 final v = ((a, b) {return 42;})(1, 2); |
| 6847 '''); | 6931 '''); |
| 6848 _assertUnlinkedConst(variable.constExpr, | 6932 _assertUnlinkedConst(variable.constExpr, |
| (...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8941 UnlinkedExecutable f = | 9025 UnlinkedExecutable f = |
| 8942 serializeExecutableText('set f(int value) {}', executableName: 'f='); | 9026 serializeExecutableText('set f(int value) {}', executableName: 'f='); |
| 8943 expect(f.inferredReturnTypeSlot, 0); | 9027 expect(f.inferredReturnTypeSlot, 0); |
| 8944 } | 9028 } |
| 8945 | 9029 |
| 8946 test_slot_reuse() { | 9030 test_slot_reuse() { |
| 8947 // Different compilation units have independent notions of slot id, so slot | 9031 // Different compilation units have independent notions of slot id, so slot |
| 8948 // ids should be reused. | 9032 // ids should be reused. |
| 8949 addNamedSource('/a.dart', 'part of foo; final v = 0;'); | 9033 addNamedSource('/a.dart', 'part of foo; final v = 0;'); |
| 8950 serializeLibraryText('library foo; part "a.dart"; final w = 0;'); | 9034 serializeLibraryText('library foo; part "a.dart"; final w = 0;'); |
| 8951 expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1); | 9035 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, |
| 8952 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1); | 9036 unlinkedUnits[0].variables[0].propagatedTypeSlot); |
| 8953 } | 9037 } |
| 8954 | 9038 |
| 8955 test_syntheticFunctionType_genericClosure() { | 9039 test_syntheticFunctionType_genericClosure() { |
| 8956 if (skipFullyLinkedData) { | 9040 if (skipFullyLinkedData) { |
| 8957 return; | 9041 return; |
| 8958 } | 9042 } |
| 8959 if (!strongMode) { | 9043 if (!strongMode) { |
| 8960 // The test below uses generic comment syntax because proper generic | 9044 // The test below uses generic comment syntax because proper generic |
| 8961 // method syntax doesn't support generic closures. So it can only run in | 9045 // method syntax doesn't support generic closures. So it can only run in |
| 8962 // strong mode. | 9046 // strong mode. |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10014 class _PrefixExpectation { | 10098 class _PrefixExpectation { |
| 10015 final ReferenceKind kind; | 10099 final ReferenceKind kind; |
| 10016 final String name; | 10100 final String name; |
| 10017 final String absoluteUri; | 10101 final String absoluteUri; |
| 10018 final String relativeUri; | 10102 final String relativeUri; |
| 10019 final int numTypeParameters; | 10103 final int numTypeParameters; |
| 10020 | 10104 |
| 10021 _PrefixExpectation(this.kind, this.name, | 10105 _PrefixExpectation(this.kind, this.name, |
| 10022 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 10106 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 10023 } | 10107 } |
| OLD | NEW |