Rewrite AST for implicit instance creation.

R=brianwilkerson@google.com

Change-Id: I2fc7b75e2d64359c3bd79fdb613f03d01e8211a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99482
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/ast_resolver.dart b/pkg/analyzer/lib/src/summary2/ast_resolver.dart
index ab43e11..a8a0d5a 100644
--- a/pkg/analyzer/lib/src/summary2/ast_resolver.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_resolver.dart
@@ -21,6 +21,7 @@
     AstNode node, {
     ClassElement enclosingClassElement,
     ExecutableElement enclosingExecutableElement,
+    bool doAstRewrite = false,
   }) {
     var source = _FakeSource();
     var errorListener = AnalysisErrorListener.NULL_LISTENER;
@@ -30,7 +31,13 @@
         nameScope: _nameScope);
     node.accept(typeResolverVisitor);
 
-//    expression.accept(_astRewriteVisitor);
+    if (doAstRewrite) {
+      var astRewriteVisitor = new AstRewriteVisitor(_linker.typeSystem,
+          _library, source, _linker.typeProvider, errorListener,
+          nameScope: _nameScope);
+      node.accept(astRewriteVisitor);
+    }
+
 //    expression.accept(_variableResolverVisitor);
 //    if (_linker.getAst != null) {
 //      expression.accept(_partialResolverVisitor);
diff --git a/pkg/analyzer/lib/src/summary2/top_level_inference.dart b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
index 1a7812e..60b10d9 100644
--- a/pkg/analyzer/lib/src/summary2/top_level_inference.dart
+++ b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
@@ -157,7 +157,7 @@
 
   void _resolveInitializer() {
     var astResolver = AstResolver(_walker._linker, _library, _scope);
-    astResolver.resolve(_node.initializer);
+    astResolver.resolve(_node.initializer, doAstRewrite: true);
   }
 }
 
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
index b64ab66..e96ea0a 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
@@ -119,12 +119,6 @@
 
   @override
   @failingTest
-  test_implicitConstructor_named_const() async {
-    await super.test_implicitConstructor_named_const();
-  }
-
-  @override
-  @failingTest
   test_import_short_absolute() async {
     // TODO(scheglov) fails on Windows
     fail('test_import_short_absolute on Windows');
@@ -133,12 +127,6 @@
 
   @override
   @failingTest
-  test_inferredType_implicitCreation() async {
-    await super.test_inferredType_implicitCreation();
-  }
-
-  @override
-  @failingTest
   test_nameConflict_importWithRelativeUri_exportWithAbsolute() async {
     // TODO(scheglov) unexpectedly passes on Windows
     fail('unexpectedly passes on Windows');
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 381cad8..b049e24 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -17,7 +17,6 @@
 import 'package:analyzer/src/test_utilities/mock_sdk.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
 import 'package:test/test.dart';
-import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import '../../util/element_type_matchers.dart';
 import 'element_text.dart';
@@ -6043,9 +6042,7 @@
 ''');
   }
 
-  @failingTest
   test_implicitConstructor_named_const() async {
-    // TODO(paulberry, scheglov): get this to pass
     var library = await checkLibrary('''
 class C {
   final Object x;
@@ -6053,7 +6050,27 @@
 }
 const x = C.named(42);
 ''');
-    checkElementText(library, 'TODO(paulberry, scheglov)');
+    if (isAstBasedSummary) {
+      checkElementText(library, r'''
+class C {
+  final Object x;
+  const C.named(Object this.x);
+}
+const C x =
+        C/*location: test.dart;C*/.
+        named/*location: test.dart;C;named*/(42);
+''');
+    } else {
+      checkElementText(library, r'''
+class C {
+  final Object x;
+  const C.named(Object this.x);
+}
+const C x = const
+        C/*location: test.dart;C*/.
+        named/*location: test.dart;C;named*/(42);
+''');
+    }
   }
 
   test_implicitTopLevelVariable_getterFirst() async {
@@ -6262,8 +6279,7 @@
 ''');
   }
 
-  void test_infer_generic_typedef_complex() async {
-    // TODO(paulberry, scheglov): get this test to pass.
+  test_infer_generic_typedef_complex() async {
     var library = await checkLibrary('''
 typedef F<T> = D<T,U> Function<U>();
 class C<V> {
@@ -6287,7 +6303,7 @@
 ''');
   }
 
-  void test_infer_generic_typedef_simple() async {
+  test_infer_generic_typedef_simple() async {
     var library = await checkLibrary('''
 typedef F = D<T> Function<T>();
 class C {
@@ -6367,7 +6383,7 @@
   }
 
   test_inference_issue_32394() async {
-    // Test the type inference involed in dartbug.com/32394
+    // Test the type inference involved in dartbug.com/32394
     var library = await checkLibrary('''
 var x = y.map((a) => a.toString());
 var y = [3];
@@ -6725,19 +6741,11 @@
 var a1 = foo.A();
 var a2 = foo.A.named();
 ''');
-    if (isAstBasedSummary) {
-      checkElementText(library, r'''
-import 'foo.dart' as foo;
-dynamic a1;
-dynamic a2;
-''');
-    } else {
-      checkElementText(library, r'''
+    checkElementText(library, r'''
 import 'foo.dart' as foo;
 A a1;
 A a2;
 ''');
-    }
   }
 
   test_inferredType_usesSyntheticFunctionType_functionTypedParam() async {