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

Unified Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1722723002: Strengthen resynthesis checks for `prefix.className.staticMember`. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/resynthesize_test.dart
diff --git a/pkg/analyzer/test/src/summary/resynthesize_test.dart b/pkg/analyzer/test/src/summary/resynthesize_test.dart
index 74a9f9f966d23cf131b2e17016c5980c02fb3708..8b1e4dd45c46111d0f37b176df389705e0e567cc 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart
@@ -53,6 +53,17 @@ class ResynthTest extends ResolverTestCase {
otherLibrarySources.add(addNamedSource(filePath, contents));
}
+ /**
+ * Verify that the given prefix is safe to elide from a resynthesized AST.
+ */
+ void checkElidablePrefix(SimpleIdentifier prefix) {
+ if (prefix.staticElement is! PrefixElement &&
+ prefix.staticElement is! ClassElement) {
+ fail('Prefix of type ${prefix.staticElement.runtimeType}'
+ ' should not have been elided');
+ }
+ }
+
void checkLibrary(String text,
{bool allowErrors: false, bool dumpSummaries: false}) {
Source source = addSource(text);
@@ -367,14 +378,9 @@ class ResynthTest extends ResolverTestCase {
// expression was e.g. `prefix.topLevelVariableName.length`, it will get
// resynthesized as `topLevelVariableName.length`
PrefixedIdentifier oTarget = o.target;
- if (oTarget.prefix.staticElement is PrefixElement ||
- oTarget.prefix.staticElement is ClassElement) {
- compareConstAsts(r,
- AstFactory.identifier(oTarget.identifier, o.propertyName), desc);
- } else {
- fail('Prefix of type ${oTarget.prefix.staticElement.runtimeType}'
- ' should not have been elided');
- }
+ checkElidablePrefix(oTarget.prefix);
+ compareConstAsts(
+ r, AstFactory.identifier(oTarget.identifier, o.propertyName), desc);
} else if (o is PrefixedIdentifier && r is PrefixedIdentifier) {
compareConstAsts(r.prefix, o.prefix, desc);
compareConstAsts(r.identifier, o.identifier, desc);
@@ -383,9 +389,15 @@ class ResynthTest extends ResolverTestCase {
expect(r.propertyName.name, o.propertyName.name, reason: desc);
compareElements(
r.propertyName.staticElement, o.propertyName.staticElement, desc);
- } else if (o is PropertyAccess && r is SimpleIdentifier) {
- // We don't resynthesize property access.
- // We use simple identifiers with correct elements.
+ } else if (o is PropertyAccess &&
+ o.target is PrefixedIdentifier &&
+ r is SimpleIdentifier) {
+ // We don't resynthesize property access when it takes the form
+ // `prefixName.className.staticMember`. We just resynthesize a
+ // SimpleIdentifier correctly resolved to the static member.
+ PrefixedIdentifier oTarget = o.target;
+ checkElidablePrefix(oTarget.prefix);
+ checkElidablePrefix(oTarget.identifier);
compareConstAsts(r, o.propertyName, desc);
} else if (o is NullLiteral) {
expect(r, new isInstanceOf<NullLiteral>(), reason: desc);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698