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

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

Issue 1864753002: Use isValidConst flag to distinguish between const / final expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge and tweaks. Created 4 years, 8 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
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 context.computeLibraryElement(context.sourceFactory.forUri(uri)); 140 context.computeLibraryElement(context.sourceFactory.forUri(uri));
141 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 141 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
142 encodeLibraryElement(original), uri, original); 142 encodeLibraryElement(original), uri, original);
143 checkLibraryElements(original, resynthesized); 143 checkLibraryElements(original, resynthesized);
144 } 144 }
145 } 145 }
146 146
147 @reflectiveTest 147 @reflectiveTest
148 abstract class ResynthesizeTest extends AbstractSingleUnitTest { 148 abstract class ResynthesizeTest extends AbstractSingleUnitTest {
149 Set<Source> otherLibrarySources = new Set<Source>(); 149 Set<Source> otherLibrarySources = new Set<Source>();
150 bool constantInitializersAreInvalid = false;
150 151
151 bool get checkPropagatedTypes => true; 152 bool get checkPropagatedTypes => true;
152 153
153 void addLibrary(String uri) { 154 void addLibrary(String uri) {
154 otherLibrarySources.add(context.sourceFactory.forUri(uri)); 155 otherLibrarySources.add(context.sourceFactory.forUri(uri));
155 } 156 }
156 157
157 void addLibrarySource(String filePath, String contents) { 158 void addLibrarySource(String filePath, String contents) {
158 otherLibrarySources.add(addSource(filePath, contents)); 159 otherLibrarySources.add(addSource(filePath, contents));
159 } 160 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 expect(rItem.value, oItem.value); 424 expect(rItem.value, oItem.value);
424 } else if (rItem is InterpolationExpression && 425 } else if (rItem is InterpolationExpression &&
425 oItem is InterpolationExpression) { 426 oItem is InterpolationExpression) {
426 compareConstAsts(rItem.expression, oItem.expression, desc); 427 compareConstAsts(rItem.expression, oItem.expression, desc);
427 } else if (rItem is MapLiteralEntry && oItem is MapLiteralEntry) { 428 } else if (rItem is MapLiteralEntry && oItem is MapLiteralEntry) {
428 compareConstAsts(rItem.key, oItem.key, desc); 429 compareConstAsts(rItem.key, oItem.key, desc);
429 compareConstAsts(rItem.value, oItem.value, desc); 430 compareConstAsts(rItem.value, oItem.value, desc);
430 } else if (oItem is ConstructorFieldInitializer && 431 } else if (oItem is ConstructorFieldInitializer &&
431 rItem is ConstructorFieldInitializer) { 432 rItem is ConstructorFieldInitializer) {
432 compareConstAsts(rItem.fieldName, oItem.fieldName, desc); 433 compareConstAsts(rItem.fieldName, oItem.fieldName, desc);
433 compareConstAsts(rItem.expression, oItem.expression, desc); 434 if (constantInitializersAreInvalid) {
435 _assertUnresolvedIdentifier(rItem.expression, desc);
436 } else {
437 compareConstAsts(rItem.expression, oItem.expression, desc);
438 }
434 } else if (oItem is SuperConstructorInvocation && 439 } else if (oItem is SuperConstructorInvocation &&
435 rItem is SuperConstructorInvocation) { 440 rItem is SuperConstructorInvocation) {
436 compareElements(rItem.staticElement, oItem.staticElement, desc); 441 compareElements(rItem.staticElement, oItem.staticElement, desc);
437 compareConstAsts(rItem.constructorName, oItem.constructorName, desc); 442 compareConstAsts(rItem.constructorName, oItem.constructorName, desc);
438 compareConstAstLists( 443 compareConstAstLists(
439 rItem.argumentList.arguments, oItem.argumentList.arguments, desc); 444 rItem.argumentList.arguments, oItem.argumentList.arguments, desc);
440 } else if (oItem is RedirectingConstructorInvocation && 445 } else if (oItem is RedirectingConstructorInvocation &&
441 rItem is RedirectingConstructorInvocation) { 446 rItem is RedirectingConstructorInvocation) {
442 compareElements(rItem.staticElement, oItem.staticElement, desc); 447 compareElements(rItem.staticElement, oItem.staticElement, desc);
443 compareConstAsts(rItem.constructorName, oItem.constructorName, desc); 448 compareConstAsts(rItem.constructorName, oItem.constructorName, desc);
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 VariableElementImpl originalActual = getActualElement(original, desc); 1161 VariableElementImpl originalActual = getActualElement(original, desc);
1157 compareFunctionElements(resynthesizedActual.initializer, 1162 compareFunctionElements(resynthesizedActual.initializer,
1158 originalActual.initializer, '$desc initializer'); 1163 originalActual.initializer, '$desc initializer');
1159 if (originalActual is ConstVariableElement) { 1164 if (originalActual is ConstVariableElement) {
1160 Element oEnclosing = original.enclosingElement; 1165 Element oEnclosing = original.enclosingElement;
1161 if (oEnclosing is ClassElement && oEnclosing.isEnum) { 1166 if (oEnclosing is ClassElement && oEnclosing.isEnum) {
1162 compareConstValues( 1167 compareConstValues(
1163 resynthesized.constantValue, original.constantValue, desc); 1168 resynthesized.constantValue, original.constantValue, desc);
1164 } else { 1169 } else {
1165 Expression initializer = resynthesizedActual.constantInitializer; 1170 Expression initializer = resynthesizedActual.constantInitializer;
1166 compareConstAsts(initializer, originalActual.constantInitializer, 1171 if (constantInitializersAreInvalid) {
1167 '$desc initializer'); 1172 _assertUnresolvedIdentifier(initializer, desc);
1173 } else {
1174 compareConstAsts(initializer, originalActual.constantInitializer,
1175 '$desc initializer');
1176 }
1168 } 1177 }
1169 } 1178 }
1170 checkPossibleMember(resynthesized, original, desc); 1179 checkPossibleMember(resynthesized, original, desc);
1171 checkPossibleLocalElements(resynthesized, original); 1180 checkPossibleLocalElements(resynthesized, original);
1172 } 1181 }
1173 1182
1174 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK; 1183 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
1175 1184
1176 /** 1185 /**
1177 * Determine the analysis options that should be used for this test. 1186 * Determine the analysis options that should be used for this test.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 return false; 1293 return false;
1285 } 1294 }
1286 } 1295 }
1287 1296
1288 @override 1297 @override
1289 void setUp() { 1298 void setUp() {
1290 super.setUp(); 1299 super.setUp();
1291 prepareAnalysisContext(createOptions()); 1300 prepareAnalysisContext(createOptions());
1292 } 1301 }
1293 1302
1294 test_const_invalid_field_const() {
1295 checkLibrary(
1296 r'''
1297 class C {
1298 static const f = 1 + foo();
1299 }
1300 int foo() => 42;
1301 ''',
1302 allowErrors: true);
1303 }
1304
1305 test_class_abstract() { 1303 test_class_abstract() {
1306 checkLibrary('abstract class C {}'); 1304 checkLibrary('abstract class C {}');
1307 } 1305 }
1308 1306
1309 test_class_alias() { 1307 test_class_alias() {
1310 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); 1308 checkLibrary('class C = D with E, F; class D {} class E {} class F {}');
1311 } 1309 }
1312 1310
1313 test_class_alias_abstract() { 1311 test_class_alias_abstract() {
1314 checkLibrary('abstract class C = D with E; class D {} class E {}'); 1312 checkLibrary('abstract class C = D with E; class D {} class E {}');
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 1630
1633 test_closure_executable_with_return_type_from_closure() { 1631 test_closure_executable_with_return_type_from_closure() {
1634 checkLibrary(''' 1632 checkLibrary('''
1635 f() { 1633 f() {
1636 print(() {}); 1634 print(() {});
1637 print(() => () => 0); 1635 print(() => () => 0);
1638 } 1636 }
1639 '''); 1637 ''');
1640 } 1638 }
1641 1639
1642 test_const_invalid_field_final() { 1640 test_const_invalid_field_const() {
1641 constantInitializersAreInvalid = true;
1643 checkLibrary( 1642 checkLibrary(
1644 r''' 1643 r'''
1645 class C { 1644 class C {
1645 static const f = 1 + foo();
1646 }
1647 int foo() => 42;
1648 ''',
1649 allowErrors: true);
1650 }
1651
1652 test_const_invalid_field_final() {
1653 constantInitializersAreInvalid = true;
1654 checkLibrary(
1655 r'''
1656 class C {
1646 final f = 1 + foo(); 1657 final f = 1 + foo();
1647 } 1658 }
1648 int foo() => 42; 1659 int foo() => 42;
1649 ''', 1660 ''',
1650 allowErrors: true); 1661 allowErrors: true);
1651 } 1662 }
1652 1663
1653 test_const_invalid_topLevel() { 1664 test_const_invalid_topLevel() {
1665 constantInitializersAreInvalid = true;
1654 checkLibrary( 1666 checkLibrary(
1655 r''' 1667 r'''
1656 const v = 1 + foo(); 1668 const v = 1 + foo();
1657 int foo() => 42; 1669 int foo() => 42;
1658 ''', 1670 ''',
1659 allowErrors: true); 1671 allowErrors: true);
1660 } 1672 }
1661 1673
1662 test_const_invokeConstructor_generic_named() { 1674 test_const_invokeConstructor_generic_named() {
1663 checkLibrary(r''' 1675 checkLibrary(r'''
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 test_constructor_initializers_field() { 2398 test_constructor_initializers_field() {
2387 checkLibrary(''' 2399 checkLibrary('''
2388 class C { 2400 class C {
2389 final x; 2401 final x;
2390 const C() : x = 42; 2402 const C() : x = 42;
2391 } 2403 }
2392 '''); 2404 ''');
2393 } 2405 }
2394 2406
2395 test_constructor_initializers_field_notConst() { 2407 test_constructor_initializers_field_notConst() {
2408 constantInitializersAreInvalid = true;
2396 checkLibrary( 2409 checkLibrary(
2397 ''' 2410 '''
2398 class C { 2411 class C {
2399 final x; 2412 final x;
2400 const A() : x = foo(); 2413 const A() : x = foo();
2401 } 2414 }
2402 int foo() => 42; 2415 int foo() => 42;
2403 ''', 2416 ''',
2404 allowErrors: true); 2417 allowErrors: true);
2405 } 2418 }
(...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after
4286 fail('Unexpectedly tried to get unlinked summary for $uri'); 4299 fail('Unexpectedly tried to get unlinked summary for $uri');
4287 } 4300 }
4288 return serializedUnit; 4301 return serializedUnit;
4289 } 4302 }
4290 4303
4291 @override 4304 @override
4292 bool hasLibrarySummary(String uri) { 4305 bool hasLibrarySummary(String uri) {
4293 return true; 4306 return true;
4294 } 4307 }
4295 } 4308 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698