Instantiate parameterized types of type parameters with 'dynamic' type arguments.

There is internal code like the added test, which caused us to use
out of scope type parameter during inferred type computation.

Possibly related issues.
https://github.com/dart-lang/sdk/issues/26990
https://github.com/dart-lang/sdk/issues/27072

R=brianwilkerson@google.com, leafp@google.com, paulberry@google.com
BUG=

Review URL: https://codereview.chromium.org/2376213003 .
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 4118d8d..9cb2c7b 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -8130,21 +8130,6 @@
   List<UnlinkedTypeParam> get unlinkedTypeParams;
 
   /**
-   * Determine the default value of type argument [i]. in most cases this will
-   * be `dynamic`, but sometimes it will be the bound of the ith type parameter.
-   */
-  DartType computeDefaultTypeArgument(int i) {
-    // If strong mode is off, or we can tell quickly from the summary that there
-    // is no bound, then the default type argument is `dynamic`; we don't have
-    // to call `typeParameters` to find that out.
-    if (!context.analysisOptions.strongMode ||
-        (unlinkedTypeParams != null && unlinkedTypeParams[i].bound == null)) {
-      return DynamicTypeImpl.instance;
-    }
-    return typeParameters[i].bound ?? DynamicTypeImpl.instance;
-  }
-
-  /**
    * Convert the given [index] into a type parameter type.
    */
   TypeParameterType getTypeParameterType(int index) {
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 41b01150..42f2994 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -606,14 +606,14 @@
       DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
     int numTypeParameters = _unlinkedClass.typeParameters.length;
     if (numTypeParameters != 0) {
-      return new InterfaceTypeImpl.elementWithNameAndArgs(this, name, () {
-        List<DartType> typeArguments = new List<DartType>(numTypeParameters);
-        for (int i = 0; i < numTypeParameters; i++) {
-          typeArguments[i] =
-              getTypeArgument(i) ?? computeDefaultTypeArgument(i);
-        }
-        return typeArguments;
-      });
+      List<DartType> typeArguments =
+          new List<DartType>.generate(numTypeParameters, getTypeArgument);
+      if (typeArguments.contains(null)) {
+        return context.typeSystem.instantiateToBounds(this.type);
+      } else {
+        return new InterfaceTypeImpl.elementWithNameAndArgs(
+            this, name, () => typeArguments);
+      }
     } else {
       return _type ??= new InterfaceTypeImpl(this);
     }
@@ -3177,12 +3177,15 @@
       DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
     int numTypeParameters = _unlinkedTypedef.typeParameters.length;
     if (numTypeParameters != 0) {
-      List<DartType> typeArguments = new List<DartType>(numTypeParameters);
-      for (int i = 0; i < numTypeParameters; i++) {
-        typeArguments[i] = getTypeArgument(i) ?? computeDefaultTypeArgument(i);
+      List<DartType> typeArguments =
+          new List<DartType>.generate(numTypeParameters, getTypeArgument);
+      if (typeArguments.contains(null)) {
+        return context.typeSystem
+            .instantiateToBounds(new FunctionTypeImpl.forTypedef(this));
+      } else {
+        return new FunctionTypeImpl.elementWithNameAndArgs(
+            this, name, typeArguments, true);
       }
-      return new FunctionTypeImpl.elementWithNameAndArgs(
-          this, name, typeArguments, true);
     } else {
       return _type ??= new FunctionTypeImpl.forTypedef(this);
     }
@@ -4407,6 +4410,9 @@
    */
   TypeInferenceNode get asTypeInferenceNode => null;
 
+  @override
+  ElementLocation get location => new ElementLocationImpl.con1(this);
+
   /**
    * Return the type indicated by this element when it is used in a
    * type instantiation context.  If this element can't legally be
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
index 126abe5..d547b6b 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
@@ -154,12 +154,6 @@
 
   @override
   @failingTest
-  void test_constructors_inferenceFBounded() {
-    super.test_constructors_inferenceFBounded();
-  }
-
-  @override
-  @failingTest
   void test_constructors_inferFromArguments() {
     // TODO(jmesserly): does this need to be implemented in AST summaries?
     // The test might need a change as well to not be based on local variable
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index aeebef5..88b8985 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -3578,6 +3578,10 @@
     checkLibrary('''
 class C<T extends C<T>> {}
 C c;
+var c2 = new C();
+class B {
+  var c3 = new C();
+}
 ''');
   }