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

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

Issue 1737903005: Properly resynthesize ClassElementImpl.hasBeenInferred. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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_strong_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 test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 @reflectiveTest 37 @reflectiveTest
38 class ResynthTest extends ResolverTestCase { 38 class ResynthTest extends ResolverTestCase {
39 Set<Source> otherLibrarySources = new Set<Source>(); 39 Set<Source> otherLibrarySources = new Set<Source>();
40 bool constantInitializersAreInvalid = false; 40 bool constantInitializersAreInvalid = false;
41 41
42 /** 42 /**
43 * Determine the analysis options that should be used for this test. 43 * Determine the analysis options that should be used for this test.
44 */ 44 */
45 AnalysisOptionsImpl get options => 45 AnalysisOptionsImpl createOptions() =>
46 new AnalysisOptionsImpl()..enableGenericMethods = true; 46 new AnalysisOptionsImpl()..enableGenericMethods = true;
47 47
48 void addLibrary(String uri) { 48 void addLibrary(String uri) {
49 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri)); 49 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri));
50 } 50 }
51 51
52 void addLibrarySource(String filePath, String contents) { 52 void addLibrarySource(String filePath, String contents) {
53 otherLibrarySources.add(addNamedSource(filePath, contents)); 53 otherLibrarySources.add(addNamedSource(filePath, contents));
54 } 54 }
55 55
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 resynthesized.accessors[i], 226 resynthesized.accessors[i],
227 original.accessors[i], 227 original.accessors[i],
228 '$desc accessor ${original.accessors[i].name}'); 228 '$desc accessor ${original.accessors[i].name}');
229 } 229 }
230 expect(resynthesized.methods.length, original.methods.length); 230 expect(resynthesized.methods.length, original.methods.length);
231 for (int i = 0; i < resynthesized.methods.length; i++) { 231 for (int i = 0; i < resynthesized.methods.length; i++) {
232 compareMethodElements(resynthesized.methods[i], original.methods[i], 232 compareMethodElements(resynthesized.methods[i], original.methods[i],
233 '$desc.${original.methods[i].name}'); 233 '$desc.${original.methods[i].name}');
234 } 234 }
235 compareTypes(resynthesized.type, original.type, desc); 235 compareTypes(resynthesized.type, original.type, desc);
236 expect(resynthesized.hasBeenInferred, original.hasBeenInferred,
237 reason: desc);
236 } 238 }
237 239
238 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized, 240 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized,
239 CompilationUnitElementImpl original) { 241 CompilationUnitElementImpl original) {
240 String desc = 'Compilation unit ${original.source.uri}'; 242 String desc = 'Compilation unit ${original.source.uri}';
241 compareUriReferencedElements(resynthesized, original, desc); 243 compareUriReferencedElements(resynthesized, original, desc);
242 expect(resynthesized.source, original.source); 244 expect(resynthesized.source, original.source);
243 expect(resynthesized.librarySource, original.librarySource); 245 expect(resynthesized.librarySource, original.librarySource);
244 expect(resynthesized.types.length, original.types.length); 246 expect(resynthesized.types.length, original.types.length);
245 for (int i = 0; i < resynthesized.types.length; i++) { 247 for (int i = 0; i < resynthesized.types.length; i++) {
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 print('Linked $path: ${JSON.encode(canonicalize(lib))}'); 1080 print('Linked $path: ${JSON.encode(canonicalize(lib))}');
1079 }); 1081 });
1080 } 1082 }
1081 return new _TestSummaryResynthesizer( 1083 return new _TestSummaryResynthesizer(
1082 null, 1084 null,
1083 analysisContext, 1085 analysisContext,
1084 analysisContext.typeProvider, 1086 analysisContext.typeProvider,
1085 analysisContext.sourceFactory, 1087 analysisContext.sourceFactory,
1086 unlinkedSummaries, 1088 unlinkedSummaries,
1087 linkedSummaries, 1089 linkedSummaries,
1088 options.strongMode); 1090 createOptions().strongMode);
1089 } 1091 }
1090 1092
1091 fail_library_hasExtUri() { 1093 fail_library_hasExtUri() {
1092 checkLibrary('import "dart-ext:doesNotExist.dart";'); 1094 checkLibrary('import "dart-ext:doesNotExist.dart";');
1093 } 1095 }
1094 1096
1095 ElementImpl getActualElement(Element element, String desc) { 1097 ElementImpl getActualElement(Element element, String desc) {
1096 if (element == null) { 1098 if (element == null) {
1097 return null; 1099 return null;
1098 } else if (element is ElementImpl) { 1100 } else if (element is ElementImpl) {
(...skipping 24 matching lines...) Expand all
1123 String uri, 1125 String uri,
1124 LibraryElement original) { 1126 LibraryElement original) {
1125 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); 1127 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri);
1126 checkMinimalResynthesisWork(resynthesizer, original); 1128 checkMinimalResynthesisWork(resynthesizer, original);
1127 return resynthesized; 1129 return resynthesized;
1128 } 1130 }
1129 1131
1130 @override 1132 @override
1131 void setUp() { 1133 void setUp() {
1132 super.setUp(); 1134 super.setUp();
1133 resetWithOptions(options); 1135 resetWithOptions(createOptions());
1134 } 1136 }
1135 1137
1136 test_class_abstract() { 1138 test_class_abstract() {
1137 checkLibrary('abstract class C {}'); 1139 checkLibrary('abstract class C {}');
1138 } 1140 }
1139 1141
1140 test_class_alias() { 1142 test_class_alias() {
1141 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); 1143 checkLibrary('class C = D with E, F; class D {} class E {} class F {}');
1142 } 1144 }
1143 1145
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2504 test_constructor_redirected_thisInvocation_unnamed_generic() { 2506 test_constructor_redirected_thisInvocation_unnamed_generic() {
2505 checkLibrary(''' 2507 checkLibrary('''
2506 class C<T> { 2508 class C<T> {
2507 C(); 2509 C();
2508 C.named() : this(); 2510 C.named() : this();
2509 } 2511 }
2510 '''); 2512 ''');
2511 } 2513 }
2512 2514
2513 test_core() { 2515 test_core() {
2516 if (createOptions().strongMode) {
2517 // The fake `dart:core` library is always in spec mode, so don't bother
2518 // trying to check that it resynthesizes properly; it won't.
2519 return;
2520 }
2514 String uri = 'dart:core'; 2521 String uri = 'dart:core';
2515 LibraryElementImpl original = 2522 LibraryElementImpl original =
2516 resolve2(analysisContext2.sourceFactory.forUri(uri)); 2523 resolve2(analysisContext2.sourceFactory.forUri(uri));
2517 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 2524 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
2518 encodeLibraryElement(original), uri, original); 2525 encodeLibraryElement(original), uri, original);
2519 checkLibraryElements(original, resynthesized); 2526 checkLibraryElements(original, resynthesized);
2520 } 2527 }
2521 2528
2522 test_enum_documented() { 2529 test_enum_documented() {
2523 checkLibrary(''' 2530 checkLibrary('''
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 2769
2763 test_function_return_type_implicit() { 2770 test_function_return_type_implicit() {
2764 checkLibrary('f() => null;'); 2771 checkLibrary('f() => null;');
2765 } 2772 }
2766 2773
2767 test_function_return_type_void() { 2774 test_function_return_type_void() {
2768 checkLibrary('void f() {}'); 2775 checkLibrary('void f() {}');
2769 } 2776 }
2770 2777
2771 test_function_type_parameter() { 2778 test_function_type_parameter() {
2772 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 2779 resetWithOptions(createOptions()..enableGenericMethods = true);
2773 checkLibrary('T f<T, U>(U u) => null;'); 2780 checkLibrary('T f<T, U>(U u) => null;');
2774 } 2781 }
2775 2782
2776 test_function_type_parameter_with_function_typed_parameter() { 2783 test_function_type_parameter_with_function_typed_parameter() {
2777 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 2784 resetWithOptions(createOptions()..enableGenericMethods = true);
2778 checkLibrary('void f<T, U>(T x(U u)) {}'); 2785 checkLibrary('void f<T, U>(T x(U u)) {}');
2779 } 2786 }
2780 2787
2781 test_functions() { 2788 test_functions() {
2782 checkLibrary('f() {} g() {}'); 2789 checkLibrary('f() {} g() {}');
2783 } 2790 }
2784 2791
2785 test_generic_gClass_gMethodStatic() { 2792 test_generic_gClass_gMethodStatic() {
2786 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 2793 resetWithOptions(createOptions()..enableGenericMethods = true);
2787 checkLibrary(''' 2794 checkLibrary('''
2788 class C<T, U> { 2795 class C<T, U> {
2789 static void m<V, W>(V v, W w) { 2796 static void m<V, W>(V v, W w) {
2790 void f<X, Y>(V v, W w, X x, Y y) { 2797 void f<X, Y>(V v, W w, X x, Y y) {
2791 } 2798 }
2792 } 2799 }
2793 } 2800 }
2794 '''); 2801 ''');
2795 } 2802 }
2796 2803
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 checkLibrary(''' 2983 checkLibrary('''
2977 class C<U, V> { 2984 class C<U, V> {
2978 void set x(value) { 2985 void set x(value) {
2979 print(() => () => 0); 2986 print(() => () => 0);
2980 } 2987 }
2981 } 2988 }
2982 '''); 2989 ''');
2983 } 2990 }
2984 2991
2985 test_inferred_function_type_in_generic_closure() { 2992 test_inferred_function_type_in_generic_closure() {
2986 if (!options.strongMode) { 2993 if (!createOptions().strongMode) {
2987 // The test below uses generic comment syntax because proper generic 2994 // The test below uses generic comment syntax because proper generic
2988 // method syntax doesn't support generic closures. So it can only run in 2995 // method syntax doesn't support generic closures. So it can only run in
2989 // strong mode. 2996 // strong mode.
2990 // TODO(paulberry): once proper generic method syntax supports generic 2997 // TODO(paulberry): once proper generic method syntax supports generic
2991 // closures, rewrite the test below without using generic comment syntax, 2998 // closures, rewrite the test below without using generic comment syntax,
2992 // and remove this hack. See dartbug.com/25819 2999 // and remove this hack. See dartbug.com/25819
2993 return; 3000 return;
2994 } 3001 }
2995 // In the code below, `<U, V>() => () => 0` has an inferred return type of 3002 // In the code below, `<U, V>() => () => 0` has an inferred return type of
2996 // `() => int`, with 3 (unused) type parameters. 3003 // `() => int`, with 3 (unused) type parameters.
2997 checkLibrary(''' 3004 checkLibrary('''
2998 f<T>() { 3005 f<T>() {
2999 print(/*<U, V>*/() => () => 0); 3006 print(/*<U, V>*/() => () => 0);
3000 } 3007 }
3001 '''); 3008 ''');
3002 } 3009 }
3003 3010
3004 test_inferred_generic_function_type_in_generic_closure() { 3011 test_inferred_generic_function_type_in_generic_closure() {
3005 if (!options.strongMode) { 3012 if (!createOptions().strongMode) {
3006 // The test below uses generic comment syntax because proper generic 3013 // The test below uses generic comment syntax because proper generic
3007 // method syntax doesn't support generic closures. So it can only run in 3014 // method syntax doesn't support generic closures. So it can only run in
3008 // strong mode. 3015 // strong mode.
3009 // TODO(paulberry): once proper generic method syntax supports generic 3016 // TODO(paulberry): once proper generic method syntax supports generic
3010 // closures, rewrite the test below without using generic comment syntax, 3017 // closures, rewrite the test below without using generic comment syntax,
3011 // and remove this hack. See dartbug.com/25819 3018 // and remove this hack. See dartbug.com/25819
3012 return; 3019 return;
3013 } 3020 }
3014 // In the code below, `<U, V>() => <W, X, Y, Z>() => 0` has an inferred 3021 // In the code below, `<U, V>() => <W, X, Y, Z>() => 0` has an inferred
3015 // return type of `() => int`, with 7 (unused) type parameters. 3022 // return type of `() => int`, with 7 (unused) type parameters.
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
3451 3458
3452 test_method_parameter_return_type() { 3459 test_method_parameter_return_type() {
3453 checkLibrary('class C { f(int g()) {} }'); 3460 checkLibrary('class C { f(int g()) {} }');
3454 } 3461 }
3455 3462
3456 test_method_parameter_return_type_void() { 3463 test_method_parameter_return_type_void() {
3457 checkLibrary('class C { f(void g()) {} }'); 3464 checkLibrary('class C { f(void g()) {} }');
3458 } 3465 }
3459 3466
3460 test_method_type_parameter() { 3467 test_method_type_parameter() {
3461 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 3468 resetWithOptions(createOptions()..enableGenericMethods = true);
3462 checkLibrary('class C { T f<T, U>(U u) => null; }'); 3469 checkLibrary('class C { T f<T, U>(U u) => null; }');
3463 } 3470 }
3464 3471
3465 test_method_type_parameter_in_generic_class() { 3472 test_method_type_parameter_in_generic_class() {
3466 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 3473 resetWithOptions(createOptions()..enableGenericMethods = true);
3467 checkLibrary('class C<T, U> { V f<V, W>(T t, U u, W w) => null; }'); 3474 checkLibrary('class C<T, U> { V f<V, W>(T t, U u, W w) => null; }');
3468 } 3475 }
3469 3476
3470 test_method_type_parameter_with_function_typed_parameter() { 3477 test_method_type_parameter_with_function_typed_parameter() {
3471 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 3478 resetWithOptions(createOptions()..enableGenericMethods = true);
3472 checkLibrary('class C { void f<T, U>(T x(U u)) {} }'); 3479 checkLibrary('class C { void f<T, U>(T x(U u)) {} }');
3473 } 3480 }
3474 3481
3475 test_nested_generic_functions_in_generic_class_with_function_typed_params() { 3482 test_nested_generic_functions_in_generic_class_with_function_typed_params() {
3476 checkLibrary(''' 3483 checkLibrary('''
3477 class C<T, U> { 3484 class C<T, U> {
3478 void g<V, W>() { 3485 void g<V, W>() {
3479 void h<X, Y>(void p(T t, U u, V v, W w, X x, Y y)) { 3486 void h<X, Y>(void p(T t, U u, V v, W w, X x, Y y)) {
3480 } 3487 }
3481 } 3488 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3639 3646
3640 test_setter_inferred_type_top_level_implicit_return() { 3647 test_setter_inferred_type_top_level_implicit_return() {
3641 checkLibrary('set f(int value) {}'); 3648 checkLibrary('set f(int value) {}');
3642 } 3649 }
3643 3650
3644 test_setters() { 3651 test_setters() {
3645 checkLibrary('void set x(int value) {} set y(value) {}'); 3652 checkLibrary('void set x(int value) {} set y(value) {}');
3646 } 3653 }
3647 3654
3648 test_syntheticFunctionType_genericClosure() { 3655 test_syntheticFunctionType_genericClosure() {
3649 if (!options.strongMode) { 3656 if (!createOptions().strongMode) {
3650 // The test below uses generic comment syntax because proper generic 3657 // The test below uses generic comment syntax because proper generic
3651 // method syntax doesn't support generic closures. So it can only run in 3658 // method syntax doesn't support generic closures. So it can only run in
3652 // strong mode. 3659 // strong mode.
3653 // TODO(paulberry): once proper generic method syntax supports generic 3660 // TODO(paulberry): once proper generic method syntax supports generic
3654 // closures, rewrite the test below without using generic comment syntax, 3661 // closures, rewrite the test below without using generic comment syntax,
3655 // and remove this hack. See dartbug.com/25819 3662 // and remove this hack. See dartbug.com/25819
3656 return; 3663 return;
3657 } 3664 }
3658 checkLibrary(''' 3665 checkLibrary('''
3659 final v = f() ? /*<T>*/(T t) => 0 : /*<T>*/(T t) => 1; 3666 final v = f() ? /*<T>*/(T t) => 0 : /*<T>*/(T t) => 1;
3660 bool f() => true; 3667 bool f() => true;
3661 '''); 3668 ''');
3662 } 3669 }
3663 3670
3664 test_syntheticFunctionType_genericClosure_inGenericFunction() { 3671 test_syntheticFunctionType_genericClosure_inGenericFunction() {
3665 if (!options.strongMode) { 3672 if (!createOptions().strongMode) {
3666 // The test below uses generic comment syntax because proper generic 3673 // The test below uses generic comment syntax because proper generic
3667 // method syntax doesn't support generic closures. So it can only run in 3674 // method syntax doesn't support generic closures. So it can only run in
3668 // strong mode. 3675 // strong mode.
3669 // TODO(paulberry): once proper generic method syntax supports generic 3676 // TODO(paulberry): once proper generic method syntax supports generic
3670 // closures, rewrite the test below without using generic comment syntax, 3677 // closures, rewrite the test below without using generic comment syntax,
3671 // and remove this hack. See dartbug.com/25819 3678 // and remove this hack. See dartbug.com/25819
3672 return; 3679 return;
3673 } 3680 }
3674 checkLibrary(''' 3681 checkLibrary('''
3675 void f<T, U>(bool b) { 3682 void f<T, U>(bool b) {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
4068 fail('Unexpectedly tried to get unlinked summary for $uri'); 4075 fail('Unexpectedly tried to get unlinked summary for $uri');
4069 } 4076 }
4070 return serializedUnit; 4077 return serializedUnit;
4071 } 4078 }
4072 4079
4073 @override 4080 @override
4074 bool hasLibrarySummary(String uri) { 4081 bool hasLibrarySummary(String uri) {
4075 return true; 4082 return true;
4076 } 4083 }
4077 } 4084 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_strong_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698