OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); | 1611 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); |
1612 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1612 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
1613 BlockFunctionBody body = | 1613 BlockFunctionBody body = |
1614 function.functionExpression.body as BlockFunctionBody; | 1614 function.functionExpression.body as BlockFunctionBody; |
1615 var statement = body.block.statements[0] as VariableDeclarationStatement; | 1615 var statement = body.block.statements[0] as VariableDeclarationStatement; |
1616 SimpleIdentifier variableName = statement.variables.variables[0].name; | 1616 SimpleIdentifier variableName = statement.variables.variables[0].name; |
1617 expect(variableName.propagatedType, isNull); | 1617 expect(variableName.propagatedType, isNull); |
1618 } | 1618 } |
1619 | 1619 |
1620 test_invocation_target_prefixed() async { | 1620 test_invocation_target_prefixed() async { |
1621 addNamedSource( | 1621 addNamedSource('/helper.dart', ''' |
1622 '/helper.dart', | |
1623 ''' | |
1624 library helper; | 1622 library helper; |
1625 int max(int x, int y) => 0; | 1623 int max(int x, int y) => 0; |
1626 '''); | 1624 '''); |
1627 String code = ''' | 1625 String code = ''' |
1628 import 'helper.dart' as helper; | 1626 import 'helper.dart' as helper; |
1629 main() { | 1627 main() { |
1630 helper.max(10, 10); // marker | 1628 helper.max(10, 10); // marker |
1631 }'''; | 1629 }'''; |
1632 CompilationUnit unit = await resolveSource(code); | 1630 CompilationUnit unit = await resolveSource(code); |
1633 SimpleIdentifier methodName = | 1631 SimpleIdentifier methodName = |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 print(x.y); // GOOD | 2174 print(x.y); // GOOD |
2177 } | 2175 } |
2178 x = null; | 2176 x = null; |
2179 }'''); | 2177 }'''); |
2180 await computeAnalysisResult(source); | 2178 await computeAnalysisResult(source); |
2181 assertNoErrors(source); | 2179 assertNoErrors(source); |
2182 } | 2180 } |
2183 | 2181 |
2184 test_objectAccessInference_disabled_for_library_prefix() async { | 2182 test_objectAccessInference_disabled_for_library_prefix() async { |
2185 String name = 'hashCode'; | 2183 String name = 'hashCode'; |
2186 addNamedSource( | 2184 addNamedSource('/helper.dart', ''' |
2187 '/helper.dart', | |
2188 ''' | |
2189 library helper; | 2185 library helper; |
2190 dynamic get $name => 42; | 2186 dynamic get $name => 42; |
2191 '''); | 2187 '''); |
2192 String code = ''' | 2188 String code = ''' |
2193 import 'helper.dart' as helper; | 2189 import 'helper.dart' as helper; |
2194 main() { | 2190 main() { |
2195 helper.$name; // marker | 2191 helper.$name; // marker |
2196 }'''; | 2192 }'''; |
2197 | 2193 |
2198 CompilationUnit unit = await resolveSource(code); | 2194 CompilationUnit unit = await resolveSource(code); |
(...skipping 25 matching lines...) Expand all Loading... |
2224 }'''; | 2220 }'''; |
2225 CompilationUnit unit = await resolveSource(code); | 2221 CompilationUnit unit = await resolveSource(code); |
2226 PropertyAccess access = | 2222 PropertyAccess access = |
2227 findMarkedIdentifier(code, unit, "; // marker").parent; | 2223 findMarkedIdentifier(code, unit, "; // marker").parent; |
2228 expect(access.staticType, typeProvider.dynamicType); | 2224 expect(access.staticType, typeProvider.dynamicType); |
2229 expect(access.realTarget.staticType, typeProvider.dynamicType); | 2225 expect(access.realTarget.staticType, typeProvider.dynamicType); |
2230 } | 2226 } |
2231 | 2227 |
2232 test_objectMethodInference_disabled_for_library_prefix() async { | 2228 test_objectMethodInference_disabled_for_library_prefix() async { |
2233 String name = 'toString'; | 2229 String name = 'toString'; |
2234 addNamedSource( | 2230 addNamedSource('/helper.dart', ''' |
2235 '/helper.dart', | |
2236 ''' | |
2237 library helper; | 2231 library helper; |
2238 dynamic $name = (int x) => x + 42'); | 2232 dynamic $name = (int x) => x + 42'); |
2239 '''); | 2233 '''); |
2240 String code = ''' | 2234 String code = ''' |
2241 import 'helper.dart' as helper; | 2235 import 'helper.dart' as helper; |
2242 main() { | 2236 main() { |
2243 helper.$name(); // marker | 2237 helper.$name(); // marker |
2244 }'''; | 2238 }'''; |
2245 CompilationUnit unit = await resolveSource(code); | 2239 CompilationUnit unit = await resolveSource(code); |
2246 SimpleIdentifier methodName = | 2240 SimpleIdentifier methodName = |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2674 expect(vd.variables.type.toString(), 'A'); | 2668 expect(vd.variables.type.toString(), 'A'); |
2675 // The initializer is not resolved. | 2669 // The initializer is not resolved. |
2676 VariableDeclaration v = vd.variables.variables[0]; | 2670 VariableDeclaration v = vd.variables.variables[0]; |
2677 var vi = v.initializer as InstanceCreationExpression; | 2671 var vi = v.initializer as InstanceCreationExpression; |
2678 expect(vi.constructorName.type.type, isNull); | 2672 expect(vi.constructorName.type.type, isNull); |
2679 } | 2673 } |
2680 } | 2674 } |
2681 | 2675 |
2682 test_modeLocal_noContext() async { | 2676 test_modeLocal_noContext() async { |
2683 CompilationUnit unit; | 2677 CompilationUnit unit; |
2684 _resolveTypeModeLocal( | 2678 _resolveTypeModeLocal(r''' |
2685 r''' | |
2686 class C { | 2679 class C { |
2687 A f = new A(); | 2680 A f = new A(); |
2688 A m([A p = const A()]) { | 2681 A m([A p = const A()]) { |
2689 A v; | 2682 A v; |
2690 } | 2683 } |
2691 } | 2684 } |
2692 A f([A p = const A()]) { | 2685 A f([A p = const A()]) { |
2693 A v1 = new A(); | 2686 A v1 = new A(); |
2694 A f2(A p2) { | 2687 A f2(A p2) { |
2695 A v2; | 2688 A v2; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2788 expect(g.returnType.type, isNull); | 2781 expect(g.returnType.type, isNull); |
2789 // The body is resolved. | 2782 // The body is resolved. |
2790 var gb = g.functionExpression.body as ExpressionFunctionBody; | 2783 var gb = g.functionExpression.body as ExpressionFunctionBody; |
2791 var ge = gb.expression as InstanceCreationExpression; | 2784 var ge = gb.expression as InstanceCreationExpression; |
2792 expect(ge.constructorName.type.type.toString(), 'A'); | 2785 expect(ge.constructorName.type.type.toString(), 'A'); |
2793 } | 2786 } |
2794 } | 2787 } |
2795 | 2788 |
2796 test_modeLocal_withContext_bad_methodBody() async { | 2789 test_modeLocal_withContext_bad_methodBody() async { |
2797 expect(() { | 2790 expect(() { |
2798 _resolveTypeModeLocal( | 2791 _resolveTypeModeLocal(r''' |
2799 r''' | |
2800 class C<T1> { | 2792 class C<T1> { |
2801 A m<T2>() { | 2793 A m<T2>() { |
2802 T1 v1; | 2794 T1 v1; |
2803 T2 v2; | 2795 T2 v2; |
2804 } | 2796 } |
2805 } | 2797 } |
2806 ''', (CompilationUnit u) { | 2798 ''', (CompilationUnit u) { |
2807 var c = u.declarations[0] as ClassDeclaration; | 2799 var c = u.declarations[0] as ClassDeclaration; |
2808 var m = c.members[0] as MethodDeclaration; | 2800 var m = c.members[0] as MethodDeclaration; |
2809 var mb = m.body as BlockFunctionBody; | 2801 var mb = m.body as BlockFunctionBody; |
2810 return mb; | 2802 return mb; |
2811 }); | 2803 }); |
2812 }, throwsStateError); | 2804 }, throwsStateError); |
2813 } | 2805 } |
2814 | 2806 |
2815 test_modeLocal_withContext_bad_topLevelVariable_declaration() async { | 2807 test_modeLocal_withContext_bad_topLevelVariable_declaration() async { |
2816 expect(() { | 2808 expect(() { |
2817 _resolveTypeModeLocal( | 2809 _resolveTypeModeLocal(r''' |
2818 r''' | |
2819 var v = new A(); | 2810 var v = new A(); |
2820 ''', (CompilationUnit u) { | 2811 ''', (CompilationUnit u) { |
2821 var tlv = u.declarations[0] as TopLevelVariableDeclaration; | 2812 var tlv = u.declarations[0] as TopLevelVariableDeclaration; |
2822 return tlv.variables.variables[0]; | 2813 return tlv.variables.variables[0]; |
2823 }); | 2814 }); |
2824 }, throwsStateError); | 2815 }, throwsStateError); |
2825 } | 2816 } |
2826 | 2817 |
2827 test_modeLocal_withContext_bad_topLevelVariable_initializer() async { | 2818 test_modeLocal_withContext_bad_topLevelVariable_initializer() async { |
2828 expect(() { | 2819 expect(() { |
2829 _resolveTypeModeLocal( | 2820 _resolveTypeModeLocal(r''' |
2830 r''' | |
2831 var v = new A(); | 2821 var v = new A(); |
2832 ''', (CompilationUnit u) { | 2822 ''', (CompilationUnit u) { |
2833 var tlv = u.declarations[0] as TopLevelVariableDeclaration; | 2823 var tlv = u.declarations[0] as TopLevelVariableDeclaration; |
2834 return tlv.variables.variables[0].initializer; | 2824 return tlv.variables.variables[0].initializer; |
2835 }); | 2825 }); |
2836 }, throwsStateError); | 2826 }, throwsStateError); |
2837 } | 2827 } |
2838 | 2828 |
2839 test_modeLocal_withContext_class() async { | 2829 test_modeLocal_withContext_class() async { |
2840 ClassDeclaration c; | 2830 ClassDeclaration c; |
2841 _resolveTypeModeLocal( | 2831 _resolveTypeModeLocal(r''' |
2842 r''' | |
2843 class C<T1> { | 2832 class C<T1> { |
2844 A m<T2>() { | 2833 A m<T2>() { |
2845 T1 v1; | 2834 T1 v1; |
2846 T2 v2; | 2835 T2 v2; |
2847 } | 2836 } |
2848 } | 2837 } |
2849 ''', (CompilationUnit u) { | 2838 ''', (CompilationUnit u) { |
2850 c = u.declarations[0] as ClassDeclaration; | 2839 c = u.declarations[0] as ClassDeclaration; |
2851 return c; | 2840 return c; |
2852 }); | 2841 }); |
(...skipping 13 matching lines...) Expand all Loading... |
2866 | 2855 |
2867 // The type of "v2" is resolved. | 2856 // The type of "v2" is resolved. |
2868 { | 2857 { |
2869 var vd = ms[1] as VariableDeclarationStatement; | 2858 var vd = ms[1] as VariableDeclarationStatement; |
2870 expect(vd.variables.type.type.toString(), 'T2'); | 2859 expect(vd.variables.type.type.toString(), 'T2'); |
2871 } | 2860 } |
2872 } | 2861 } |
2873 | 2862 |
2874 test_modeLocal_withContext_inClass_constructor() async { | 2863 test_modeLocal_withContext_inClass_constructor() async { |
2875 ConstructorDeclaration cc; | 2864 ConstructorDeclaration cc; |
2876 _resolveTypeModeLocal( | 2865 _resolveTypeModeLocal(r''' |
2877 r''' | |
2878 class C<T> { | 2866 class C<T> { |
2879 C() { | 2867 C() { |
2880 T v1; | 2868 T v1; |
2881 } | 2869 } |
2882 } | 2870 } |
2883 ''', (CompilationUnit u) { | 2871 ''', (CompilationUnit u) { |
2884 var c = u.declarations[0] as ClassDeclaration; | 2872 var c = u.declarations[0] as ClassDeclaration; |
2885 cc = c.members[0] as ConstructorDeclaration; | 2873 cc = c.members[0] as ConstructorDeclaration; |
2886 return cc; | 2874 return cc; |
2887 }); | 2875 }); |
2888 | 2876 |
2889 var ccb = cc.body as BlockFunctionBody; | 2877 var ccb = cc.body as BlockFunctionBody; |
2890 var ccs = ccb.block.statements; | 2878 var ccs = ccb.block.statements; |
2891 | 2879 |
2892 // The type of "v" is resolved. | 2880 // The type of "v" is resolved. |
2893 { | 2881 { |
2894 var vd = ccs[0] as VariableDeclarationStatement; | 2882 var vd = ccs[0] as VariableDeclarationStatement; |
2895 expect(vd.variables.type.type.toString(), 'T'); | 2883 expect(vd.variables.type.type.toString(), 'T'); |
2896 } | 2884 } |
2897 } | 2885 } |
2898 | 2886 |
2899 test_modeLocal_withContext_inClass_method() async { | 2887 test_modeLocal_withContext_inClass_method() async { |
2900 MethodDeclaration m; | 2888 MethodDeclaration m; |
2901 _resolveTypeModeLocal( | 2889 _resolveTypeModeLocal(r''' |
2902 r''' | |
2903 class C<T1> { | 2890 class C<T1> { |
2904 A m<T2>() { | 2891 A m<T2>() { |
2905 T1 v1; | 2892 T1 v1; |
2906 T2 v2; | 2893 T2 v2; |
2907 } | 2894 } |
2908 } | 2895 } |
2909 ''', (CompilationUnit u) { | 2896 ''', (CompilationUnit u) { |
2910 var c = u.declarations[0] as ClassDeclaration; | 2897 var c = u.declarations[0] as ClassDeclaration; |
2911 m = c.members[0] as MethodDeclaration; | 2898 m = c.members[0] as MethodDeclaration; |
2912 return m; | 2899 return m; |
(...skipping 13 matching lines...) Expand all Loading... |
2926 | 2913 |
2927 // The type of "v2" is resolved. | 2914 // The type of "v2" is resolved. |
2928 { | 2915 { |
2929 var vd = ms[1] as VariableDeclarationStatement; | 2916 var vd = ms[1] as VariableDeclarationStatement; |
2930 expect(vd.variables.type.type.toString(), 'T2'); | 2917 expect(vd.variables.type.type.toString(), 'T2'); |
2931 } | 2918 } |
2932 } | 2919 } |
2933 | 2920 |
2934 test_modeLocal_withContext_topLevelFunction() async { | 2921 test_modeLocal_withContext_topLevelFunction() async { |
2935 FunctionDeclaration f; | 2922 FunctionDeclaration f; |
2936 _resolveTypeModeLocal( | 2923 _resolveTypeModeLocal(r''' |
2937 r''' | |
2938 A m<T>() { | 2924 A m<T>() { |
2939 T v; | 2925 T v; |
2940 } | 2926 } |
2941 ''', (CompilationUnit u) { | 2927 ''', (CompilationUnit u) { |
2942 f = u.declarations[0] as FunctionDeclaration; | 2928 f = u.declarations[0] as FunctionDeclaration; |
2943 return f; | 2929 return f; |
2944 }); | 2930 }); |
2945 | 2931 |
2946 // The return type of "f" is not resolved. | 2932 // The return type of "f" is not resolved. |
2947 expect(f.returnType.type, isNull); | 2933 expect(f.returnType.type, isNull); |
2948 | 2934 |
2949 var fb = f.functionExpression.body as BlockFunctionBody; | 2935 var fb = f.functionExpression.body as BlockFunctionBody; |
2950 var fs = fb.block.statements; | 2936 var fs = fb.block.statements; |
2951 | 2937 |
2952 // The type of "v" is resolved. | 2938 // The type of "v" is resolved. |
2953 var vd = fs[0] as VariableDeclarationStatement; | 2939 var vd = fs[0] as VariableDeclarationStatement; |
2954 expect(vd.variables.type.type.toString(), 'T'); | 2940 expect(vd.variables.type.type.toString(), 'T'); |
2955 } | 2941 } |
2956 | 2942 |
2957 test_modeLocal_withContext_topLevelVariable() async { | 2943 test_modeLocal_withContext_topLevelVariable() async { |
2958 TopLevelVariableDeclaration v; | 2944 TopLevelVariableDeclaration v; |
2959 _resolveTypeModeLocal( | 2945 _resolveTypeModeLocal(r''' |
2960 r''' | |
2961 A v = new A(); | 2946 A v = new A(); |
2962 ''', (CompilationUnit u) { | 2947 ''', (CompilationUnit u) { |
2963 v = u.declarations[0] as TopLevelVariableDeclaration; | 2948 v = u.declarations[0] as TopLevelVariableDeclaration; |
2964 return v; | 2949 return v; |
2965 }); | 2950 }); |
2966 | 2951 |
2967 // The type of "v" is not resolved. | 2952 // The type of "v" is not resolved. |
2968 expect(v.variables.type.type, isNull); | 2953 expect(v.variables.type.type, isNull); |
2969 | 2954 |
2970 // The type of "v" initializer is resolved. | 2955 // The type of "v" initializer is resolved. |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3613 */ | 3598 */ |
3614 class _StaleElement extends ElementImpl { | 3599 class _StaleElement extends ElementImpl { |
3615 _StaleElement() : super("_StaleElement", -1); | 3600 _StaleElement() : super("_StaleElement", -1); |
3616 | 3601 |
3617 @override | 3602 @override |
3618 get kind => throw "_StaleElement's kind shouldn't be accessed"; | 3603 get kind => throw "_StaleElement's kind shouldn't be accessed"; |
3619 | 3604 |
3620 @override | 3605 @override |
3621 T accept<T>(_) => throw "_StaleElement shouldn't be visited"; | 3606 T accept<T>(_) => throw "_StaleElement shouldn't be visited"; |
3622 } | 3607 } |
OLD | NEW |