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

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

Issue 1937223002: All initializer expressions are serialized, even if not all of them are constants. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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_ast_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/constant/value.dart'; 10 import 'package:analyzer/dart/constant/value.dart';
(...skipping 24 matching lines...) Expand all
35 main() { 35 main() {
36 groupSep = ' | '; 36 groupSep = ' | ';
37 runReflectiveTests(ResynthesizeElementTest); 37 runReflectiveTests(ResynthesizeElementTest);
38 } 38 }
39 39
40 /** 40 /**
41 * Abstract base class for resynthesizing and comparing elements. 41 * Abstract base class for resynthesizing and comparing elements.
42 */ 42 */
43 abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest { 43 abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest {
44 Set<Source> otherLibrarySources = new Set<Source>(); 44 Set<Source> otherLibrarySources = new Set<Source>();
45 bool constantInitializersAreInvalid = false;
46 45
47 bool get checkPropagatedTypes => true; 46 bool get checkPropagatedTypes => true;
48 47
49 /** 48 /**
50 * Derived classes can override this getter to return `true` in order to 49 * Derived classes can override this getter to return `true` in order to
51 * cause certain checks to be skipped if they are known to fail with 50 * cause certain checks to be skipped if they are known to fail with
52 * AST-based type inference. 51 * AST-based type inference.
53 * 52 *
54 * TODO(paulberry): remove this flag once AST-based type inference is fully 53 * TODO(paulberry): remove this flag once AST-based type inference is fully
55 * working. 54 * working.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 expect(rItem.value, oItem.value); 327 expect(rItem.value, oItem.value);
329 } else if (rItem is InterpolationExpression && 328 } else if (rItem is InterpolationExpression &&
330 oItem is InterpolationExpression) { 329 oItem is InterpolationExpression) {
331 compareConstAsts(rItem.expression, oItem.expression, desc); 330 compareConstAsts(rItem.expression, oItem.expression, desc);
332 } else if (rItem is MapLiteralEntry && oItem is MapLiteralEntry) { 331 } else if (rItem is MapLiteralEntry && oItem is MapLiteralEntry) {
333 compareConstAsts(rItem.key, oItem.key, desc); 332 compareConstAsts(rItem.key, oItem.key, desc);
334 compareConstAsts(rItem.value, oItem.value, desc); 333 compareConstAsts(rItem.value, oItem.value, desc);
335 } else if (oItem is ConstructorFieldInitializer && 334 } else if (oItem is ConstructorFieldInitializer &&
336 rItem is ConstructorFieldInitializer) { 335 rItem is ConstructorFieldInitializer) {
337 compareConstAsts(rItem.fieldName, oItem.fieldName, desc); 336 compareConstAsts(rItem.fieldName, oItem.fieldName, desc);
338 if (constantInitializersAreInvalid) { 337 compareConstAsts(rItem.expression, oItem.expression, desc);
339 _assertUnresolvedIdentifier(rItem.expression, desc);
340 } else {
341 compareConstAsts(rItem.expression, oItem.expression, desc);
342 }
343 } else if (oItem is SuperConstructorInvocation && 338 } else if (oItem is SuperConstructorInvocation &&
344 rItem is SuperConstructorInvocation) { 339 rItem is SuperConstructorInvocation) {
345 compareElements(rItem.staticElement, oItem.staticElement, desc); 340 compareElements(rItem.staticElement, oItem.staticElement, desc);
346 compareConstAsts(rItem.constructorName, oItem.constructorName, desc); 341 compareConstAsts(rItem.constructorName, oItem.constructorName, desc);
347 compareConstAstLists( 342 compareConstAstLists(
348 rItem.argumentList.arguments, oItem.argumentList.arguments, desc); 343 rItem.argumentList.arguments, oItem.argumentList.arguments, desc);
349 } else if (oItem is RedirectingConstructorInvocation && 344 } else if (oItem is RedirectingConstructorInvocation &&
350 rItem is RedirectingConstructorInvocation) { 345 rItem is RedirectingConstructorInvocation) {
351 compareElements(rItem.staticElement, oItem.staticElement, desc); 346 compareElements(rItem.staticElement, oItem.staticElement, desc);
352 compareConstAsts(rItem.constructorName, oItem.constructorName, desc); 347 compareConstAsts(rItem.constructorName, oItem.constructorName, desc);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // resynthesized as `topLevelVariableName.length` 399 // resynthesized as `topLevelVariableName.length`
405 PrefixedIdentifier oTarget = o.target; 400 PrefixedIdentifier oTarget = o.target;
406 checkElidablePrefix(oTarget.prefix); 401 checkElidablePrefix(oTarget.prefix);
407 compareConstAsts( 402 compareConstAsts(
408 r, AstFactory.identifier(oTarget.identifier, o.propertyName), desc); 403 r, AstFactory.identifier(oTarget.identifier, o.propertyName), desc);
409 } else if (o is PrefixedIdentifier && r is PrefixedIdentifier) { 404 } else if (o is PrefixedIdentifier && r is PrefixedIdentifier) {
410 compareConstAsts(r.prefix, o.prefix, desc); 405 compareConstAsts(r.prefix, o.prefix, desc);
411 compareConstAsts(r.identifier, o.identifier, desc); 406 compareConstAsts(r.identifier, o.identifier, desc);
412 } else if (o is PropertyAccess && r is PropertyAccess) { 407 } else if (o is PropertyAccess && r is PropertyAccess) {
413 compareConstAsts(r.target, o.target, desc); 408 compareConstAsts(r.target, o.target, desc);
414 expect(r.propertyName.name, o.propertyName.name, reason: desc); 409 String oName = o.propertyName.name;
415 compareElements( 410 String rName = r.propertyName.name;
416 r.propertyName.staticElement, o.propertyName.staticElement, desc); 411 expect(rName, oName, reason: desc);
412 if (oName == 'length') {
413 compareElements(
414 r.propertyName.staticElement, o.propertyName.staticElement, desc);
415 }
417 } else if (o is PropertyAccess && 416 } else if (o is PropertyAccess &&
418 o.target is PrefixedIdentifier && 417 o.target is PrefixedIdentifier &&
419 r is SimpleIdentifier) { 418 r is SimpleIdentifier) {
420 // We don't resynthesize property access when it takes the form 419 // We don't resynthesize property access when it takes the form
421 // `prefixName.className.staticMember`. We just resynthesize a 420 // `prefixName.className.staticMember`. We just resynthesize a
422 // SimpleIdentifier correctly resolved to the static member. 421 // SimpleIdentifier correctly resolved to the static member.
423 PrefixedIdentifier oTarget = o.target; 422 PrefixedIdentifier oTarget = o.target;
424 checkElidablePrefix(oTarget.prefix); 423 checkElidablePrefix(oTarget.prefix);
425 checkElidablePrefix(oTarget.identifier); 424 checkElidablePrefix(oTarget.identifier);
426 compareConstAsts(r, o.propertyName, desc); 425 compareConstAsts(r, o.propertyName, desc);
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 compareFunctionElements(resynthesizedActual.initializer, 1071 compareFunctionElements(resynthesizedActual.initializer,
1073 originalActual.initializer, '$desc initializer'); 1072 originalActual.initializer, '$desc initializer');
1074 } 1073 }
1075 if (originalActual is ConstVariableElement) { 1074 if (originalActual is ConstVariableElement) {
1076 Element oEnclosing = original.enclosingElement; 1075 Element oEnclosing = original.enclosingElement;
1077 if (oEnclosing is ClassElement && oEnclosing.isEnum) { 1076 if (oEnclosing is ClassElement && oEnclosing.isEnum) {
1078 compareConstValues( 1077 compareConstValues(
1079 resynthesized.constantValue, original.constantValue, desc); 1078 resynthesized.constantValue, original.constantValue, desc);
1080 } else { 1079 } else {
1081 Expression initializer = resynthesizedActual.constantInitializer; 1080 Expression initializer = resynthesizedActual.constantInitializer;
1082 if (constantInitializersAreInvalid) { 1081 compareConstAsts(initializer, originalActual.constantInitializer,
1083 _assertUnresolvedIdentifier(initializer, desc); 1082 '$desc initializer');
1084 } else {
1085 compareConstAsts(initializer, originalActual.constantInitializer,
1086 '$desc initializer');
1087 }
1088 } 1083 }
1089 } 1084 }
1090 checkPossibleMember(resynthesized, original, desc); 1085 checkPossibleMember(resynthesized, original, desc);
1091 checkPossibleLocalElements(resynthesized, original); 1086 checkPossibleLocalElements(resynthesized, original);
1092 } 1087 }
1093 1088
1094 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK; 1089 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
1095 1090
1096 /** 1091 /**
1097 * Determine the analysis options that should be used for this test. 1092 * Determine the analysis options that should be used for this test.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 expect(type.isDynamic || type.isVoid, isTrue); 1188 expect(type.isDynamic || type.isVoid, isTrue);
1194 return false; 1189 return false;
1195 } 1190 }
1196 } 1191 }
1197 1192
1198 @override 1193 @override
1199 void setUp() { 1194 void setUp() {
1200 super.setUp(); 1195 super.setUp();
1201 prepareAnalysisContext(createOptions()); 1196 prepareAnalysisContext(createOptions());
1202 } 1197 }
1203
1204 void _assertUnresolvedIdentifier(Expression initializer, String desc) {
1205 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc);
1206 SimpleIdentifier identifier = initializer;
1207 expect(identifier.staticElement, isNull, reason: desc);
1208 }
1209 } 1198 }
1210 1199
1211 @reflectiveTest 1200 @reflectiveTest
1212 class ResynthesizeElementTest extends ResynthesizeTest { 1201 class ResynthesizeElementTest extends ResynthesizeTest {
1213 @override 1202 @override
1214 LibraryElementImpl checkLibrary(String text, 1203 LibraryElementImpl checkLibrary(String text,
1215 {bool allowErrors: false, bool dumpSummaries: false}) { 1204 {bool allowErrors: false, bool dumpSummaries: false}) {
1216 Source source = addTestSource(text); 1205 Source source = addTestSource(text);
1217 LibraryElementImpl original = context.computeLibraryElement(source); 1206 LibraryElementImpl original = context.computeLibraryElement(source);
1218 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 1207 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 test_closure_executable_with_return_type_from_closure() { 1650 test_closure_executable_with_return_type_from_closure() {
1662 checkLibrary(''' 1651 checkLibrary('''
1663 f() { 1652 f() {
1664 print(() {}); 1653 print(() {});
1665 print(() => () => 0); 1654 print(() => () => 0);
1666 } 1655 }
1667 '''); 1656 ''');
1668 } 1657 }
1669 1658
1670 test_const_invalid_field_const() { 1659 test_const_invalid_field_const() {
1671 constantInitializersAreInvalid = true;
1672 checkLibrary( 1660 checkLibrary(
1673 r''' 1661 r'''
1674 class C { 1662 class C {
1675 static const f = 1 + foo(); 1663 static const f = 1 + foo();
1676 } 1664 }
1677 int foo() => 42; 1665 int foo() => 42;
1678 ''', 1666 ''',
1679 allowErrors: true); 1667 allowErrors: true);
1680 } 1668 }
1681 1669
1682 test_const_invalid_field_final() { 1670 test_const_invalid_field_final() {
1683 constantInitializersAreInvalid = true;
1684 checkLibrary( 1671 checkLibrary(
1685 r''' 1672 r'''
1686 class C { 1673 class C {
1687 final f = 1 + foo(); 1674 final f = 1 + foo();
1688 } 1675 }
1689 int foo() => 42; 1676 int foo() => 42;
1690 ''', 1677 ''',
1691 allowErrors: true); 1678 allowErrors: true);
1692 } 1679 }
1693 1680
1694 test_const_invalid_topLevel() { 1681 test_const_invalid_topLevel() {
1695 constantInitializersAreInvalid = true;
1696 checkLibrary( 1682 checkLibrary(
1697 r''' 1683 r'''
1698 const v = 1 + foo(); 1684 const v = 1 + foo();
1699 int foo() => 42; 1685 int foo() => 42;
1700 ''', 1686 ''',
1701 allowErrors: true); 1687 allowErrors: true);
1702 } 1688 }
1703 1689
1704 test_const_invokeConstructor_generic_named() { 1690 test_const_invokeConstructor_generic_named() {
1705 checkLibrary(r''' 1691 checkLibrary(r'''
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 test_constructor_initializers_field() { 2414 test_constructor_initializers_field() {
2429 checkLibrary(''' 2415 checkLibrary('''
2430 class C { 2416 class C {
2431 final x; 2417 final x;
2432 const C() : x = 42; 2418 const C() : x = 42;
2433 } 2419 }
2434 '''); 2420 ''');
2435 } 2421 }
2436 2422
2437 test_constructor_initializers_field_notConst() { 2423 test_constructor_initializers_field_notConst() {
2438 constantInitializersAreInvalid = true;
2439 checkLibrary( 2424 checkLibrary(
2440 ''' 2425 '''
2441 class C { 2426 class C {
2442 final x; 2427 final x;
2443 const A() : x = foo(); 2428 const A() : x = foo();
2444 } 2429 }
2445 int foo() => 42; 2430 int foo() => 42;
2446 ''', 2431 ''',
2447 allowErrors: true); 2432 allowErrors: true);
2448 } 2433 }
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
4334 fail('Unexpectedly tried to get unlinked summary for $uri'); 4319 fail('Unexpectedly tried to get unlinked summary for $uri');
4335 } 4320 }
4336 return serializedUnit; 4321 return serializedUnit;
4337 } 4322 }
4338 4323
4339 @override 4324 @override
4340 bool hasLibrarySummary(String uri) { 4325 bool hasLibrarySummary(String uri) {
4341 return true; 4326 return true;
4342 } 4327 }
4343 } 4328 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_ast_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698