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

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

Issue 1681513003: Resynthesize invalid constants as unresolved identifiers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/lib/src/summary/resynthesize.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 17 matching lines...) Expand all
28 import 'summary_common.dart' show canonicalize; 28 import 'summary_common.dart' show canonicalize;
29 29
30 main() { 30 main() {
31 groupSep = ' | '; 31 groupSep = ' | ';
32 runReflectiveTests(ResynthTest); 32 runReflectiveTests(ResynthTest);
33 } 33 }
34 34
35 @reflectiveTest 35 @reflectiveTest
36 class ResynthTest extends ResolverTestCase { 36 class ResynthTest extends ResolverTestCase {
37 Set<Source> otherLibrarySources = new Set<Source>(); 37 Set<Source> otherLibrarySources = new Set<Source>();
38 bool constantInitializersAreInvalid = false;
38 39
39 /** 40 /**
40 * Determine the analysis options that should be used for this test. 41 * Determine the analysis options that should be used for this test.
41 */ 42 */
42 AnalysisOptionsImpl get options => 43 AnalysisOptionsImpl get options =>
43 new AnalysisOptionsImpl()..enableGenericMethods = true; 44 new AnalysisOptionsImpl()..enableGenericMethods = true;
44 45
45 void addLibrary(String uri) { 46 void addLibrary(String uri) {
46 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri)); 47 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri));
47 } 48 }
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 expect(resynthesized.uri, original.uri); 740 expect(resynthesized.uri, original.uri);
740 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); 741 expect(resynthesized.uriOffset, original.uriOffset, reason: desc);
741 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); 742 expect(resynthesized.uriEnd, original.uriEnd, reason: desc);
742 } 743 }
743 744
744 void compareVariableElements(VariableElementImpl resynthesized, 745 void compareVariableElements(VariableElementImpl resynthesized,
745 VariableElementImpl original, String desc) { 746 VariableElementImpl original, String desc) {
746 compareElements(resynthesized, original, desc); 747 compareElements(resynthesized, original, desc);
747 compareTypes(resynthesized.type, original.type, desc); 748 compareTypes(resynthesized.type, original.type, desc);
748 if (original is ConstVariableElement) { 749 if (original is ConstVariableElement) {
749 compareConstantAsts(resynthesized.constantInitializer, 750 Expression initializer = resynthesized.constantInitializer;
750 original.constantInitializer, desc); 751 if (constantInitializersAreInvalid) {
752 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc);
753 SimpleIdentifier identifier = initializer;
754 expect(identifier.staticElement, isNull, reason: desc);
755 } else {
756 compareConstantAsts(initializer, original.constantInitializer, desc);
757 }
751 } 758 }
752 } 759 }
753 760
754 /** 761 /**
755 * Serialize the given [library] into a summary. Then create a 762 * Serialize the given [library] into a summary. Then create a
756 * [_TestSummaryResynthesizer] which can deserialize it, along with any 763 * [_TestSummaryResynthesizer] which can deserialize it, along with any
757 * references it makes to `dart:core`. 764 * references it makes to `dart:core`.
758 * 765 *
759 * Errors will lead to a test failure unless [allowErrors] is `true`. 766 * Errors will lead to a test failure unless [allowErrors] is `true`.
760 */ 767 */
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 } 1163 }
1157 1164
1158 test_class_type_parameters_f_bound_simple() { 1165 test_class_type_parameters_f_bound_simple() {
1159 checkLibrary('class C<T extends U, U> {}'); 1166 checkLibrary('class C<T extends U, U> {}');
1160 } 1167 }
1161 1168
1162 test_classes() { 1169 test_classes() {
1163 checkLibrary('class C {} class D {}'); 1170 checkLibrary('class C {} class D {}');
1164 } 1171 }
1165 1172
1173 test_const_invalid_field_const() {
1174 constantInitializersAreInvalid = true;
1175 checkLibrary(
1176 r'''
1177 class C {
1178 static const f = 1 + foo();
1179 }
1180 int foo() => 42;
1181 ''',
1182 allowErrors: true);
1183 }
1184
1185 test_const_invalid_field_final() {
1186 constantInitializersAreInvalid = true;
1187 checkLibrary(
1188 r'''
1189 class C {
1190 final f = 1 + foo();
1191 }
1192 int foo() => 42;
1193 ''',
1194 allowErrors: true);
1195 }
1196
1197 test_const_invalid_topLevel() {
1198 constantInitializersAreInvalid = true;
1199 checkLibrary(
1200 r'''
1201 const v = 1 + foo();
1202 int foo() => 42;
1203 ''',
1204 allowErrors: true);
1205 }
1206
1166 test_const_invokeConstructor_generic_named() { 1207 test_const_invokeConstructor_generic_named() {
1167 checkLibrary(r''' 1208 checkLibrary(r'''
1168 class C<K, V> { 1209 class C<K, V> {
1169 const C.named(K k, V v); 1210 const C.named(K k, V v);
1170 } 1211 }
1171 const V = const C<int, String>.named(1, '222'); 1212 const V = const C<int, String>.named(1, '222');
1172 '''); 1213 ''');
1173 } 1214 }
1174 1215
1175 test_const_invokeConstructor_generic_named_imported() { 1216 test_const_invokeConstructor_generic_named_imported() {
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 fail('Unexpectedly tried to get unlinked summary for $uri'); 2878 fail('Unexpectedly tried to get unlinked summary for $uri');
2838 } 2879 }
2839 return serializedUnit; 2880 return serializedUnit;
2840 } 2881 }
2841 2882
2842 @override 2883 @override
2843 bool hasLibrarySummary(String uri) { 2884 bool hasLibrarySummary(String uri) {
2844 return true; 2885 return true;
2845 } 2886 }
2846 } 2887 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698