Rework how type information is communicated from CFE to analyzer.

This CL introduces new Factory/TypeInferenceListener methods to
communicate details about types that are literally named in the source
code.

Previously, when an expression like `x as List<int>` was analyzed, the
resolution information about `List<int>` was communicated to the
analyzer via a kernel DartType, forcing the analyzer to walk the type
representation, applying each of its constituent parts to the
corresponding part of the AST for `List<int>`.  This was a lot of work
for the analyzer, it failed to resolve parts of invalid types (such as
`List<int, String>), and it didn't pave the way toward moving to the
Factory API.

The new approach is for information about each type appearing in the
syntax to be communicated to the analyzer at the time the BodyBuilder
converts it to a DartType.  So for an invalid type like `List<int,
String>`, the resolution of `String` is communicated to the analyzer
at the time it is converted to a DartType; later, when `String` is
discarded (because `List` only accepts one type parameter), no crucial
information is lost, because the analyzer already knows the resolution
of `String`.

Work still to be done has been captured in issues:
- #33844: References to type parameter elements are not translated
- #33845: Function typed formal parameters are not handled
- #33846: Function types using `Function` syntax are not yet handled

Change-Id: I96dd9b6f3eb573b0b7a46335e8644c59fb78bae7
Reviewed-on: https://dart-review.googlesource.com/64262
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index fc58691..9397292 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -774,7 +774,7 @@
               var redirectedConstructor = context.redirectedConstructor;
               redirectName.staticElement = redirectedConstructor;
               // TODO(scheglov) Support for import prefix?
-              ResolutionApplier.applyConstructorElement(
+              DeclarationResolver.applyConstructorElement(
                   _libraryElement,
                   null,
                   redirectedConstructor,
@@ -1089,12 +1089,15 @@
           invokeType: translateType(data.invokeType),
           isExplicitCall: data.isExplicitCall,
           isImplicitCall: data.isImplicitCall,
+          isTypeReference: data.isTypeReference,
           isWriteReference: data.isWriteReference,
           literalType: translateType(data.literalType),
           loadLibrary: _translateReference(data.loadLibrary),
           prefixInfo: _translatePrefixInfo(data.prefixInfo),
           reference: _translateReference(data.reference,
-              isWriteReference: data.isWriteReference),
+              isWriteReference: data.isWriteReference,
+              isTypeReference: data.isTypeReference,
+              inferredType: data.inferredType),
           writeContext: translateType(data.writeContext));
     }
 
@@ -1168,6 +1171,8 @@
       element = declaration.staticElement;
     } else if (declaration is FunctionDeclaration) {
       element = declaration.element;
+    } else if (declaration is TypeParameter) {
+      element = declaration.element;
     } else {
       throw new UnimplementedError('${declaration.runtimeType}');
     }
@@ -1181,8 +1186,15 @@
   }
 
   Element _translateReference(kernel.Node referencedNode,
-      {bool isWriteReference = false}) {
-    if (referencedNode == null) return null;
+      {bool isWriteReference = false,
+      bool isTypeReference = false,
+      kernel.DartType inferredType}) {
+    if (referencedNode == null) {
+      if (isTypeReference && inferredType is kernel.DynamicType) {
+        return typeProvider.dynamicType.element;
+      }
+      return null;
+    }
     Element element;
     if (referencedNode is kernel.NamedNode) {
       element = resynthesizer
@@ -1202,6 +1214,9 @@
       assert(element != null);
     } else if (referencedNode is kernel.DynamicType) {
       element = DynamicElementImpl.instance;
+    } else if (referencedNode is kernel.TypeParameter) {
+      // TODO(paulberry): find the corresponding element (dartbug.com/33844)
+      element = null;
     } else if (referencedNode is kernel.InvalidType) {
       element = DynamicElementImpl.instance;
     } else {
diff --git a/pkg/analyzer/lib/src/fasta/resolution_applier.dart b/pkg/analyzer/lib/src/fasta/resolution_applier.dart
index 8c189c3..0f5bf34 100644
--- a/pkg/analyzer/lib/src/fasta/resolution_applier.dart
+++ b/pkg/analyzer/lib/src/fasta/resolution_applier.dart
@@ -11,7 +11,6 @@
 import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/member.dart';
 import 'package:analyzer/src/fasta/resolution_storer.dart';
-import 'package:analyzer/src/generated/declaration_resolver.dart';
 import 'package:front_end/src/base/syntactic_entity.dart';
 import 'package:front_end/src/scanner/token.dart';
 import 'package:kernel/kernel.dart' as kernel;
@@ -105,9 +104,8 @@
   @override
   void visitAsExpression(AsExpression node) {
     node.expression.accept(this);
+    node.type.accept(this);
     var data = _get(node.asOperator);
-    applyToTypeAnnotation(
-        _enclosingLibraryElement, data.literalType, node.type);
     node.staticType = data.inferredType;
   }
 
@@ -164,12 +162,7 @@
 
   @override
   void visitCatchClause(CatchClause node) {
-    DartType guardType = _get(node.onKeyword ?? node.catchKeyword).literalType;
-    if (node.exceptionType != null) {
-      applyToTypeAnnotation(
-          _enclosingLibraryElement, guardType, node.exceptionType);
-    }
-
+    node.exceptionType?.accept(this);
     SimpleIdentifier exception = node.exceptionParameter;
     if (exception != null) {
       LocalVariableElementImpl element = exception.staticElement;
@@ -229,16 +222,12 @@
   void visitForEachStatement(ForEachStatement node) {
     DeclaredIdentifier loopVariable = node.loopVariable;
     if (loopVariable != null) {
+      loopVariable.type?.accept(this);
       SimpleIdentifier identifier = loopVariable.identifier;
 
       DartType type = _get(identifier).inferredType;
       identifier.staticType = type;
 
-      if (loopVariable.type != null) {
-        applyToTypeAnnotation(
-            _enclosingLibraryElement, type, loopVariable.type);
-      }
-
       VariableElementImpl element = identifier.staticElement;
       if (element != null) {
         _typeContext.encloseVariable(element);
@@ -256,14 +245,29 @@
   void visitFormalParameterList(FormalParameterList parameterList) {
     for (var parameter in parameterList.parameters) {
       parameter.metadata?.accept(this);
+      NormalFormalParameter normalParameter;
       if (parameter is DefaultFormalParameter) {
         parameter.defaultValue?.accept(this);
+        normalParameter = parameter.parameter;
+      } else if (parameter is NormalFormalParameter) {
+        normalParameter = parameter;
+      } else {
+        // All parameters should either be DefaultFormalParameter or
+        // NormalFormalParameter.
+        throw new UnimplementedError('${parameter.runtimeType}');
+      }
+      if (normalParameter is SimpleFormalParameter) {
+        normalParameter.type?.accept(this);
+      } else {
+        // TODO(paulberry): handle function typed formal parameters
+        // (dartbug.com/33845)
       }
     }
   }
 
   @override
   void visitFunctionDeclaration(FunctionDeclaration node) {
+    node.returnType?.accept(this);
     FunctionExpression functionExpression = node.functionExpression;
     FormalParameterList parameterList = functionExpression.parameters;
 
@@ -292,11 +296,6 @@
           typeParameter.name.staticType = _typeContext.typeType;
         }
       }
-
-      applyToTypeAnnotation(
-          _enclosingLibraryElement, element.returnType, node.returnType);
-      applyParameters(
-          _enclosingLibraryElement, element.parameters, parameterList);
     }
 
     _typeContext.exitLocalFunction(element);
@@ -319,8 +318,6 @@
     if (element != null) {
       node.element = element;
       node.staticType = element.type;
-      applyParameters(
-          _enclosingLibraryElement, element.parameters, parameterList);
     }
 
     _typeContext.exitLocalFunction(element);
@@ -329,19 +326,12 @@
   @override
   void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
     node.function.accept(this);
+    node.typeArguments?.accept(this);
 
     var data = _get(node.argumentList);
     DartType invokeType = data.invokeType;
     node.staticInvokeType = invokeType;
 
-    List<DartType> typeArguments = data.argumentTypes;
-    if (node.typeArguments != null && typeArguments != null) {
-      _applyTypeArgumentsToList(
-          _enclosingLibraryElement,
-          new TypeArgumentsDartType(typeArguments),
-          node.typeArguments.arguments);
-    }
-
     DartType resultType = data.inferredType;
     node.staticType = resultType;
 
@@ -374,6 +364,7 @@
     SimpleIdentifier classIdentifier;
     SimpleIdentifier constructorIdentifier;
 
+    constructorName.type.typeArguments?.accept(this);
     var data = _get(typeIdentifier);
     TypeName newTypeName;
     if (typeIdentifier is SimpleIdentifier) {
@@ -405,12 +396,6 @@
     ConstructorElement constructor = data.reference;
     DartType type = data.inferredType;
 
-    TypeArgumentList typeArguments = constructorName.type.typeArguments;
-    if (typeArguments != null) {
-      _applyTypeArgumentsToList(
-          _enclosingLibraryElement, type, typeArguments.arguments);
-    }
-
     node.staticElement = constructor;
     node.staticType = type;
 
@@ -429,9 +414,8 @@
   @override
   void visitIsExpression(IsExpression node) {
     node.expression.accept(this);
+    node.type.accept(this);
     var data = _get(node.isOperator);
-    applyToTypeAnnotation(
-        _enclosingLibraryElement, data.literalType, node.type);
     node.staticType = data.inferredType;
   }
 
@@ -449,26 +433,20 @@
     node.elements.accept(this);
     DartType type = _get(node.constKeyword ?? node.leftBracket).inferredType;
     node.staticType = type;
-    if (node.typeArguments != null) {
-      _applyTypeArgumentsToList(
-          _enclosingLibraryElement, type, node.typeArguments.arguments);
-    }
   }
 
   @override
   void visitMapLiteral(MapLiteral node) {
+    node.typeArguments?.accept(this);
     node.entries.accept(this);
     DartType type = _get(node.constKeyword ?? node.leftBracket).inferredType;
     node.staticType = type;
-    if (node.typeArguments != null) {
-      _applyTypeArgumentsToList(
-          _enclosingLibraryElement, type, node.typeArguments.arguments);
-    }
   }
 
   @override
   void visitMethodInvocation(MethodInvocation node) {
     node.target?.accept(this);
+    node.typeArguments?.accept(this);
 
     ArgumentList argumentList = node.argumentList;
 
@@ -486,7 +464,6 @@
       invokeElement = data.reference;
     }
     DartType invokeType = data.invokeType;
-    List<DartType> typeArguments = data.argumentTypes;
     DartType resultType = data.inferredType;
 
     if (invokeElement is PropertyInducingElement) {
@@ -506,13 +483,6 @@
       node.methodName.staticType = invokeType;
     }
 
-    if (node.typeArguments != null && typeArguments != null) {
-      _applyTypeArgumentsToList(
-          _enclosingLibraryElement,
-          new TypeArgumentsDartType(typeArguments),
-          node.typeArguments.arguments);
-    }
-
     _applyResolutionToArguments(argumentList);
 
     {
@@ -659,6 +629,12 @@
   }
 
   @override
+  void visitTypeName(TypeName node) {
+    super.visitTypeName(node);
+    node.type = node.name.staticType;
+  }
+
+  @override
   void visitVariableDeclaration(VariableDeclaration node) {
     AstNode parent = node.parent;
     if (parent is VariableDeclarationList &&
@@ -684,15 +660,9 @@
     if (node.parent is TopLevelVariableDeclaration) {
       node.variables.accept(this);
     } else {
+      node.type?.accept(this);
       node.metadata.accept(this);
       node.variables.accept(this);
-      if (node.type != null) {
-        DartType type = node.variables[0].name.staticType;
-        // TODO(brianwilkerson) Understand why the type is sometimes `null`.
-        if (type != null) {
-          applyToTypeAnnotation(_enclosingLibraryElement, type, node.type);
-        }
-      }
     }
   }
 
@@ -790,192 +760,6 @@
       }
     }
   }
-
-  /// Apply the [type] that is created by the [constructorName] and the
-  /// [constructorElement] it references.
-  static void applyConstructorElement(
-      LibraryElement enclosingLibraryElement,
-      PrefixElement prefixElement,
-      ConstructorElement constructorElement,
-      DartType type,
-      ConstructorName constructorName) {
-    constructorName.staticElement = constructorElement;
-
-    ClassElement classElement = constructorElement?.enclosingElement;
-
-    Identifier typeIdentifier = constructorName.type.name;
-    if (prefixElement != null) {
-      PrefixedIdentifier prefixedTypeIdentifier = typeIdentifier;
-      prefixedTypeIdentifier.staticType = type;
-
-      prefixedTypeIdentifier.prefix.staticElement = prefixElement;
-
-      SimpleIdentifier classNode = prefixedTypeIdentifier.identifier;
-      classNode.staticElement = classElement;
-      classNode.staticType = type;
-    } else {
-      if (typeIdentifier is SimpleIdentifier) {
-        typeIdentifier.staticElement = classElement;
-        typeIdentifier.staticType = type;
-      } else if (typeIdentifier is PrefixedIdentifier) {
-        constructorName.type = astFactory.typeName(typeIdentifier.prefix, null);
-        constructorName.period = typeIdentifier.period;
-        constructorName.name = typeIdentifier.identifier;
-      }
-    }
-
-    constructorName.name?.staticElement = constructorElement;
-
-    applyToTypeAnnotation(enclosingLibraryElement, type, constructorName.type);
-  }
-
-  /// Apply the types of the [parameterElements] to the [parameterList] that
-  /// have an explicit type annotation.
-  static void applyParameters(
-      LibraryElement enclosingLibraryElement,
-      List<ParameterElement> parameterElements,
-      FormalParameterList parameterList) {
-    List<FormalParameter> parameters = parameterList.parameters;
-
-    int length = parameterElements.length;
-    if (parameters.length != length) {
-      throw new StateError('Parameter counts do not match');
-    }
-    for (int i = 0; i < length; i++) {
-      ParameterElementImpl element = parameterElements[i];
-      FormalParameter parameter = parameters[i];
-
-      DeclarationResolver.resolveMetadata(
-          parameter, parameter.metadata, element);
-
-      NormalFormalParameter normalParameter;
-      if (parameter is NormalFormalParameter) {
-        normalParameter = parameter;
-      } else if (parameter is DefaultFormalParameter) {
-        normalParameter = parameter.parameter;
-      }
-      assert(normalParameter != null);
-
-      if (normalParameter is SimpleFormalParameterImpl) {
-        normalParameter.element = element;
-      }
-
-      if (normalParameter.identifier != null) {
-        element.nameOffset = normalParameter.identifier.offset;
-        normalParameter.identifier.staticElement = element;
-        normalParameter.identifier.staticType = element.type;
-      }
-
-      // Apply the type or the return type, if a function typed parameter.
-      TypeAnnotation functionReturnType;
-      FormalParameterList functionParameterList;
-      if (normalParameter is SimpleFormalParameter) {
-        applyToTypeAnnotation(
-            enclosingLibraryElement, element.type, normalParameter.type);
-      } else if (normalParameter is FunctionTypedFormalParameter) {
-        functionReturnType = normalParameter.returnType;
-        functionParameterList = normalParameter.parameters;
-      } else if (normalParameter is FieldFormalParameter) {
-        if (normalParameter.parameters == null) {
-          applyToTypeAnnotation(
-              enclosingLibraryElement, element.type, normalParameter.type);
-        } else {
-          functionReturnType = normalParameter.type;
-          functionParameterList = normalParameter.parameters;
-        }
-      }
-
-      if (functionParameterList != null) {
-        FunctionType elementType = element.type;
-        if (functionReturnType != null) {
-          applyToTypeAnnotation(enclosingLibraryElement, elementType.returnType,
-              functionReturnType);
-        }
-        applyParameters(enclosingLibraryElement, elementType.parameters,
-            functionParameterList);
-      }
-    }
-  }
-
-  /// Apply the [type] to the [typeAnnotation] by setting the type of the
-  /// [typeAnnotation] to the [type] and recursively applying each of the type
-  /// arguments of the [type] to the corresponding type arguments of the
-  /// [typeAnnotation].
-  static void applyToTypeAnnotation(LibraryElement enclosingLibraryElement,
-      DartType type, TypeAnnotation typeAnnotation) {
-    if (typeAnnotation is GenericFunctionTypeImpl) {
-      if (type is! FunctionType) {
-        throw new StateError('Non-function type ($type) '
-            'for generic function annotation ($typeAnnotation)');
-      }
-      FunctionType functionType = type;
-      typeAnnotation.type = type;
-      applyToTypeAnnotation(enclosingLibraryElement, functionType.returnType,
-          typeAnnotation.returnType);
-      applyParameters(enclosingLibraryElement, functionType.parameters,
-          typeAnnotation.parameters);
-    } else if (typeAnnotation is TypeNameImpl) {
-      typeAnnotation.type = type;
-
-      Identifier typeIdentifier = typeAnnotation.name;
-      SimpleIdentifier typeName;
-      if (typeIdentifier is PrefixedIdentifier) {
-        if (enclosingLibraryElement != null) {
-          String prefixName = typeIdentifier.prefix.name;
-          for (var import in enclosingLibraryElement.imports) {
-            if (import.prefix?.name == prefixName) {
-              typeIdentifier.prefix.staticElement = import.prefix;
-              break;
-            }
-          }
-        }
-        typeName = typeIdentifier.identifier;
-      } else {
-        typeName = typeIdentifier;
-      }
-
-      Element typeElement = type.element;
-      if (typeElement is GenericFunctionTypeElement &&
-          typeElement.enclosingElement is GenericTypeAliasElement) {
-        typeElement = typeElement.enclosingElement;
-      }
-
-      typeName.staticElement = typeElement;
-      typeName.staticType = type;
-    }
-    if (typeAnnotation is NamedType) {
-      TypeArgumentList typeArguments = typeAnnotation.typeArguments;
-      if (typeArguments != null) {
-        _applyTypeArgumentsToList(
-            enclosingLibraryElement, type, typeArguments.arguments);
-      }
-    }
-  }
-
-  /// Recursively apply each of the type arguments of the [type] to the
-  /// corresponding type arguments of the [typeArguments].
-  static void _applyTypeArgumentsToList(LibraryElement enclosingLibraryElement,
-      DartType type, List<TypeAnnotation> typeArguments) {
-    if (type != null && type.isUndefined) {
-      for (TypeAnnotation argument in typeArguments) {
-        applyToTypeAnnotation(enclosingLibraryElement, type, argument);
-      }
-    } else if (type is ParameterizedType) {
-      List<DartType> argumentTypes = type.typeArguments;
-      int argumentCount = argumentTypes.length;
-      if (argumentCount != typeArguments.length) {
-        throw new StateError('Found $argumentCount argument types '
-            'for ${typeArguments.length} type arguments');
-      }
-      for (int i = 0; i < argumentCount; i++) {
-        applyToTypeAnnotation(
-            enclosingLibraryElement, argumentTypes[i], typeArguments[i]);
-      }
-    } else {
-      throw new StateError('Attempting to apply a non-parameterized type '
-          '(${type.runtimeType}) to type arguments');
-    }
-  }
 }
 
 /// A container with [typeArguments].
diff --git a/pkg/analyzer/lib/src/fasta/resolution_storer.dart b/pkg/analyzer/lib/src/fasta/resolution_storer.dart
index 9f45b88..72fdf19 100644
--- a/pkg/analyzer/lib/src/fasta/resolution_storer.dart
+++ b/pkg/analyzer/lib/src/fasta/resolution_storer.dart
@@ -19,6 +19,7 @@
   final Type invokeType;
   final bool isExplicitCall;
   final bool isImplicitCall;
+  final bool isTypeReference;
   final bool isWriteReference;
   final Type literalType;
   final Reference loadLibrary;
@@ -34,6 +35,7 @@
       this.invokeType,
       this.isExplicitCall = false,
       this.isImplicitCall = false,
+      this.isTypeReference = false,
       this.isWriteReference = false,
       this.literalType,
       this.loadLibrary,
@@ -598,6 +600,21 @@
     _store(location, reference: expressionType, inferredType: inferredType);
   }
 
+  void typeReference(
+      int location,
+      Token leftBracket,
+      List<void> typeArguments,
+      Token rightBracket,
+      Node reference,
+      covariant TypeVariableBinder binder,
+      DartType type) {
+    _store(location,
+        reference: reference,
+        declaration: binder?.fileOffset,
+        inferredType: type,
+        isTypeReference: true);
+  }
+
   void typeVariableDeclaration(
       covariant TypeVariableBinder binder, TypeParameter typeParameter) {
     _storeTypeVariableDeclaration(binder.fileOffset, typeParameter);
@@ -637,6 +654,10 @@
         declaration: variableBinder?.fileOffset, inferredType: inferredType);
   }
 
+  void voidType(int location, Token token, DartType type) {
+    _store(location, inferredType: type);
+  }
+
   void whileStatement(
       StatementJudgment judgment,
       int location,
@@ -657,6 +678,7 @@
       DartType invokeType,
       bool isExplicitCall = false,
       bool isImplicitCall = false,
+      bool isTypeReference = false,
       bool isWriteReference = false,
       DartType literalType,
       Node loadLibrary,
@@ -676,6 +698,7 @@
         invokeType: invokeType,
         isExplicitCall: isExplicitCall,
         isImplicitCall: isImplicitCall,
+        isTypeReference: isTypeReference,
         isWriteReference: isWriteReference,
         literalType: literalType,
         loadLibrary: loadLibrary,
diff --git a/pkg/analyzer/lib/src/generated/declaration_resolver.dart b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
index f25218f..5afac37 100644
--- a/pkg/analyzer/lib/src/generated/declaration_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
@@ -5,6 +5,7 @@
 library analyzer.src.generated.declaration_resolver;
 
 import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/standard_ast_factory.dart';
 import 'package:analyzer/dart/ast/token.dart';
 import 'package:analyzer/dart/ast/visitor.dart';
 import 'package:analyzer/dart/element/element.dart';
@@ -14,7 +15,6 @@
 import 'package:analyzer/src/dart/element/builder.dart';
 import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/type.dart';
-import 'package:analyzer/src/fasta/resolution_applier.dart';
 import 'package:analyzer/src/generated/resolver.dart';
 
 /**
@@ -294,8 +294,7 @@
   @override
   Object visitFormalParameterList(FormalParameterList node) {
     if (_applyKernelTypes) {
-      ResolutionApplier.applyParameters(
-          _enclosingLibrary, _walker._parameters, node);
+      applyParameters(_enclosingLibrary, _walker._parameters, node);
       _walker.consumeParameters();
       return null;
     } else {
@@ -633,8 +632,7 @@
 
   /// Apply [type] to the [typeAnnotation].
   void _applyType(DartType type, TypeAnnotation typeAnnotation) {
-    ResolutionApplier.applyToTypeAnnotation(
-        _enclosingLibrary, type, typeAnnotation);
+    applyToTypeAnnotation(_enclosingLibrary, type, typeAnnotation);
   }
 
   /**
@@ -734,6 +732,168 @@
     _walker = outerWalker;
   }
 
+  /// Apply the [type] that is created by the [constructorName] and the
+  /// [constructorElement] it references.
+  static void applyConstructorElement(
+      LibraryElement enclosingLibraryElement,
+      PrefixElement prefixElement,
+      ConstructorElement constructorElement,
+      DartType type,
+      ConstructorName constructorName) {
+    constructorName.staticElement = constructorElement;
+
+    ClassElement classElement = constructorElement?.enclosingElement;
+
+    Identifier typeIdentifier = constructorName.type.name;
+    if (prefixElement != null) {
+      PrefixedIdentifier prefixedTypeIdentifier = typeIdentifier;
+      prefixedTypeIdentifier.staticType = type;
+
+      prefixedTypeIdentifier.prefix.staticElement = prefixElement;
+
+      SimpleIdentifier classNode = prefixedTypeIdentifier.identifier;
+      classNode.staticElement = classElement;
+      classNode.staticType = type;
+    } else {
+      if (typeIdentifier is SimpleIdentifier) {
+        typeIdentifier.staticElement = classElement;
+        typeIdentifier.staticType = type;
+      } else if (typeIdentifier is PrefixedIdentifier) {
+        constructorName.type = astFactory.typeName(typeIdentifier.prefix, null);
+        constructorName.period = typeIdentifier.period;
+        constructorName.name = typeIdentifier.identifier;
+      }
+    }
+
+    constructorName.name?.staticElement = constructorElement;
+
+    DeclarationResolver.applyToTypeAnnotation(
+        enclosingLibraryElement, type, constructorName.type);
+  }
+
+  /// Apply the types of the [parameterElements] to the [parameterList] that
+  /// have an explicit type annotation.
+  static void applyParameters(
+      LibraryElement enclosingLibraryElement,
+      List<ParameterElement> parameterElements,
+      FormalParameterList parameterList) {
+    List<FormalParameter> parameters = parameterList.parameters;
+
+    int length = parameterElements.length;
+    if (parameters.length != length) {
+      throw new StateError('Parameter counts do not match');
+    }
+    for (int i = 0; i < length; i++) {
+      ParameterElementImpl element = parameterElements[i];
+      FormalParameter parameter = parameters[i];
+
+      DeclarationResolver.resolveMetadata(
+          parameter, parameter.metadata, element);
+
+      NormalFormalParameter normalParameter;
+      if (parameter is NormalFormalParameter) {
+        normalParameter = parameter;
+      } else if (parameter is DefaultFormalParameter) {
+        normalParameter = parameter.parameter;
+      }
+      assert(normalParameter != null);
+
+      if (normalParameter is SimpleFormalParameterImpl) {
+        normalParameter.element = element;
+      }
+
+      if (normalParameter.identifier != null) {
+        element.nameOffset = normalParameter.identifier.offset;
+        normalParameter.identifier.staticElement = element;
+        normalParameter.identifier.staticType = element.type;
+      }
+
+      // Apply the type or the return type, if a function typed parameter.
+      TypeAnnotation functionReturnType;
+      FormalParameterList functionParameterList;
+      if (normalParameter is SimpleFormalParameter) {
+        applyToTypeAnnotation(
+            enclosingLibraryElement, element.type, normalParameter.type);
+      } else if (normalParameter is FunctionTypedFormalParameter) {
+        functionReturnType = normalParameter.returnType;
+        functionParameterList = normalParameter.parameters;
+      } else if (normalParameter is FieldFormalParameter) {
+        if (normalParameter.parameters == null) {
+          applyToTypeAnnotation(
+              enclosingLibraryElement, element.type, normalParameter.type);
+        } else {
+          functionReturnType = normalParameter.type;
+          functionParameterList = normalParameter.parameters;
+        }
+      }
+
+      if (functionParameterList != null) {
+        FunctionType elementType = element.type;
+        if (functionReturnType != null) {
+          applyToTypeAnnotation(enclosingLibraryElement, elementType.returnType,
+              functionReturnType);
+        }
+        applyParameters(enclosingLibraryElement, elementType.parameters,
+            functionParameterList);
+      }
+    }
+  }
+
+  /// Apply the [type] to the [typeAnnotation] by setting the type of the
+  /// [typeAnnotation] to the [type] and recursively applying each of the type
+  /// arguments of the [type] to the corresponding type arguments of the
+  /// [typeAnnotation].
+  static void applyToTypeAnnotation(LibraryElement enclosingLibraryElement,
+      DartType type, TypeAnnotation typeAnnotation) {
+    if (typeAnnotation is GenericFunctionTypeImpl) {
+      if (type is! FunctionType) {
+        throw new StateError('Non-function type ($type) '
+            'for generic function annotation ($typeAnnotation)');
+      }
+      FunctionType functionType = type;
+      typeAnnotation.type = type;
+      applyToTypeAnnotation(enclosingLibraryElement, functionType.returnType,
+          typeAnnotation.returnType);
+      applyParameters(enclosingLibraryElement, functionType.parameters,
+          typeAnnotation.parameters);
+    } else if (typeAnnotation is TypeNameImpl) {
+      typeAnnotation.type = type;
+
+      Identifier typeIdentifier = typeAnnotation.name;
+      SimpleIdentifier typeName;
+      if (typeIdentifier is PrefixedIdentifier) {
+        if (enclosingLibraryElement != null) {
+          String prefixName = typeIdentifier.prefix.name;
+          for (var import in enclosingLibraryElement.imports) {
+            if (import.prefix?.name == prefixName) {
+              typeIdentifier.prefix.staticElement = import.prefix;
+              break;
+            }
+          }
+        }
+        typeName = typeIdentifier.identifier;
+      } else {
+        typeName = typeIdentifier;
+      }
+
+      Element typeElement = type.element;
+      if (typeElement is GenericFunctionTypeElement &&
+          typeElement.enclosingElement is GenericTypeAliasElement) {
+        typeElement = typeElement.enclosingElement;
+      }
+
+      typeName.staticElement = typeElement;
+      typeName.staticType = type;
+    }
+    if (typeAnnotation is NamedType) {
+      TypeArgumentList typeArguments = typeAnnotation.typeArguments;
+      if (typeArguments != null) {
+        _applyTypeArgumentsToList(
+            enclosingLibraryElement, type, typeArguments.arguments);
+      }
+    }
+  }
+
   /**
    * Associate each of the annotation [nodes] with the corresponding
    * [ElementAnnotation] in [annotations]. If there is a problem, report it
@@ -767,6 +927,31 @@
     }
   }
 
+  /// Recursively apply each of the type arguments of the [type] to the
+  /// corresponding type arguments of the [typeArguments].
+  static void _applyTypeArgumentsToList(LibraryElement enclosingLibraryElement,
+      DartType type, List<TypeAnnotation> typeArguments) {
+    if (type != null && type.isUndefined) {
+      for (TypeAnnotation argument in typeArguments) {
+        applyToTypeAnnotation(enclosingLibraryElement, type, argument);
+      }
+    } else if (type is ParameterizedType) {
+      List<DartType> argumentTypes = type.typeArguments;
+      int argumentCount = argumentTypes.length;
+      if (argumentCount != typeArguments.length) {
+        throw new StateError('Found $argumentCount argument types '
+            'for ${typeArguments.length} type arguments');
+      }
+      for (int i = 0; i < argumentCount; i++) {
+        applyToTypeAnnotation(
+            enclosingLibraryElement, argumentTypes[i], typeArguments[i]);
+      }
+    } else {
+      throw new StateError('Attempting to apply a non-parameterized type '
+          '(${type.runtimeType}) to type arguments');
+    }
+  }
+
   static bool _isBodyToCreateElementsFor(FunctionBody node) {
     AstNode parent = node.parent;
     return parent is ConstructorDeclaration ||
diff --git a/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_kernel_test.dart b/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_kernel_test.dart
index 7ffb604..bb24909 100644
--- a/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_kernel_test.dart
@@ -89,6 +89,13 @@
     await super.test_fieldFormalParameterNotAssignableToField_map_keyMismatch();
   }
 
+  @override
+  @failingTest
+  test_fieldFormalParameterAssignableToField_list_nonDynamic() {
+    // Failed to resolve 1 nodes
+    return super.test_fieldFormalParameterAssignableToField_list_nonDynamic();
+  }
+
   @failingTest
   @override
   test_fieldFormalParameterNotAssignableToField_map_valueMismatch() async {
@@ -112,6 +119,13 @@
     await super.test_fieldFormalParameterNotAssignableToField_typedef();
   }
 
+  @override
+  @failingTest
+  test_fieldFormalParameterAssignableToField_typeSubstitution() {
+    // Bad state: Not found #lib1::A::T in null
+    return super.test_fieldFormalParameterAssignableToField_typeSubstitution();
+  }
+
   @failingTest
   @override
   test_fieldInitializerNotAssignable() async {
@@ -189,6 +203,13 @@
     await super.test_mapValueTypeNotAssignable();
   }
 
+  @override
+  @failingTest
+  test_parameterAssignable_typeSubstitution() {
+    // Failed to resolve 1 nodes
+    return super.test_parameterAssignable_typeSubstitution();
+  }
+
   @failingTest
   @override
   test_parameterAssignable_undefined_null() async {
diff --git a/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart
index f89ae90..85added 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart
@@ -143,6 +143,13 @@
 
   @override
   @failingTest
+  test_constConstructor_redirect_generic() {
+    // Bad state: Not found #lib4::A::T in null
+    return super.test_constConstructor_redirect_generic();
+  }
+
+  @override
+  @failingTest
   test_constConstructorWithFieldInitializedByNonConst() async {
     // Expected 1 errors of type CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST, found 0;
     //          1 errors of type CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, found 0
diff --git a/pkg/analyzer/test/generated/hint_code_kernel_test.dart b/pkg/analyzer/test/generated/hint_code_kernel_test.dart
index bfc95d5..ffd3480 100644
--- a/pkg/analyzer/test/generated/hint_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_kernel_test.dart
@@ -283,6 +283,13 @@
 
   @failingTest
   @override
+  test_unusedElement_method_isUsed_invocation_MemberElement() {
+    // Failed to resolve 1 nodes
+    return super.test_unusedElement_method_isUsed_invocation_MemberElement();
+  }
+
+  @failingTest
+  @override
   test_unusedImport_inComment_libraryDirective() async {
     // Expected 0 errors of type HintCode.UNUSED_IMPORT, found 1 (42)
     return super.test_unusedImport_inComment_libraryDirective();
diff --git a/pkg/analyzer/test/generated/non_error_resolver_kernel_test.dart b/pkg/analyzer/test/generated/non_error_resolver_kernel_test.dart
index 1c57259..56e80b6 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_kernel_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_kernel_test.dart
@@ -55,6 +55,22 @@
 
   @override
   @failingTest
+  test_argumentTypeNotAssignable_fieldFormalParameterElement_member() {
+    // Bad state: Not found #lib1::TimestampedObject::E in null
+    return super
+        .test_argumentTypeNotAssignable_fieldFormalParameterElement_member();
+  }
+
+  @override
+  @failingTest
+  test_argumentTypeNotAssignable_invocation_functionParameter_generic() {
+    // Failed to resolve 1 nodes
+    return super
+        .test_argumentTypeNotAssignable_invocation_functionParameter_generic();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/31604')
   test_commentReference_beforeConstructor() async {
     return super.test_commentReference_beforeConstructor();
@@ -134,6 +150,13 @@
 
   @override
   @failingTest
+  test_const_constructor_with_named_generic_parameter() {
+    // Failed to resolve 1 nodes
+    return super.test_const_constructor_with_named_generic_parameter();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/33676')
   test_constConstructorWithMixinWithField() {
     // Bad state: Unable to convert (Unspecified, null, @52, Can't extend a mixin application and be 'const'.)
@@ -149,6 +172,20 @@
 
   @override
   @failingTest
+  test_expectedOneListTypeArgument() {
+    // Failed to resolve 1 nodes
+    return super.test_expectedOneListTypeArgument();
+  }
+
+  @override
+  @failingTest
+  test_extraPositionalArguments_implicitConstructor() {
+    // Failed to resolve 2 nodes
+    return super.test_extraPositionalArguments_implicitConstructor();
+  }
+
+  @override
+  @failingTest
   test_fieldFormalParameter_genericFunctionTyped() {
     // Expected 0 errors of type ParserErrorCode.EXPECTED_TOKEN, found 1 (88)
     return super.test_fieldFormalParameter_genericFunctionTyped();
@@ -177,12 +214,77 @@
 
   @override
   @failingTest
+  test_forEach_genericFunctionType() {
+    // Bad state: Not found T in main() → dynamic
+    return super.test_forEach_genericFunctionType();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/33799')
   test_functionTypeAlias_scope_signature() async {
     // Caused by Bad state: Found 1 annotation nodes and 0 element annotations
     return super.test_functionTypeAlias_scope_signature();
   }
 
+  @override
+  @failingTest
+  test_genericTypeAlias_fieldAndReturnType_noTypeParameters() {
+    // Failed to resolve 1 nodes
+    return super.test_genericTypeAlias_fieldAndReturnType_noTypeParameters();
+  }
+
+  @override
+  @failingTest
+  test_genericTypeAlias_fieldAndReturnType_typeParameters_arguments() {
+    // Failed to resolve 1 nodes
+    return super
+        .test_genericTypeAlias_fieldAndReturnType_typeParameters_arguments();
+  }
+
+  @override
+  @failingTest
+  test_genericTypeAlias_fieldAndReturnType_typeParameters_noArguments() {
+    // Failed to resolve 1 nodes
+    return super
+        .test_genericTypeAlias_fieldAndReturnType_typeParameters_noArguments();
+  }
+
+  @override
+  @failingTest
+  test_genericTypeAlias_noTypeParameters() {
+    // Failed to resolve 1 nodes
+    return super.test_genericTypeAlias_noTypeParameters();
+  }
+
+  @override
+  @failingTest
+  test_genericTypeAlias_typeParameters() {
+    // Failed to resolve 1 nodes
+    return super.test_genericTypeAlias_typeParameters();
+  }
+
+  @override
+  @failingTest
+  test_implicitThisReferenceInInitializer_typeParameter() {
+    // Failed to resolve 1 nodes
+    return super.test_implicitThisReferenceInInitializer_typeParameter();
+  }
+
+  @override
+  @failingTest
+  test_inconsistentMethodInheritance_methods_typeParameter2() {
+    // Failed to resolve 3 nodes
+    return super.test_inconsistentMethodInheritance_methods_typeParameter2();
+  }
+
+  @override
+  @failingTest
+  test_inconsistentMethodInheritance_methods_typeParameters1() {
+    // Failed to resolve 3 nodes
+    return super.test_inconsistentMethodInheritance_methods_typeParameters1();
+  }
+
   @override // passes with kernel
   test_infer_mixin() => super.test_infer_mixin();
 
@@ -192,6 +294,27 @@
 
   @override
   @failingTest
+  test_invalidTypeArgumentInConstList() {
+    // Failed to resolve 1 nodes
+    return super.test_invalidTypeArgumentInConstList();
+  }
+
+  @override
+  @failingTest
+  test_invalidTypeArgumentInConstMap() {
+    // Failed to resolve 1 nodes
+    return super.test_invalidTypeArgumentInConstMap();
+  }
+
+  @override
+  @failingTest
+  test_invocationOfNonFunction_functionTypeTypeParameter() {
+    // Bad state: Not found #lib2::C::T in null
+    return super.test_invocationOfNonFunction_functionTypeTypeParameter();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/31758')
   test_invocationOfNonFunction_Object() async {
     return super.test_invocationOfNonFunction_Object();
@@ -199,6 +322,13 @@
 
   @override
   @failingTest
+  test_listElementTypeNotAssignable() {
+    // Failed to resolve 2 nodes
+    return super.test_listElementTypeNotAssignable();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/30609')
   test_metadata_enumConstantDeclaration() {
     // Failed to resolve 2 nodes
@@ -214,6 +344,13 @@
 
   @override
   @failingTest
+  test_nonConstantDefaultValue_typedConstList() {
+    // Failed to resolve 2 nodes
+    return super.test_nonConstantDefaultValue_typedConstList();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/31628')
   test_nonConstCaseExpression_constField() async {
     return super.test_nonConstCaseExpression_constField();
@@ -228,6 +365,13 @@
 
   @override
   @failingTest
+  test_nonTypeInCatchClause_isTypeParameter() {
+    // Failed to resolve 1 nodes
+    return super.test_nonTypeInCatchClause_isTypeParameter();
+  }
+
+  @override
+  @failingTest
   @notForDart2
   test_null_callMethod() async {
     return super.test_null_callMethod();
@@ -249,6 +393,20 @@
 
   @override
   @failingTest
+  test_propagateTypeArgs_intoSupertype() {
+    // Failed to resolve 4 nodes
+    return super.test_propagateTypeArgs_intoSupertype();
+  }
+
+  @override
+  @failingTest
+  test_reversedTypeArguments() {
+    // Failed to resolve 4 nodes
+    return super.test_reversedTypeArguments();
+  }
+
+  @override
+  @failingTest
   @FastaProblem('https://github.com/dart-lang/sdk/issues/33677')
   test_undefinedIdentifier_synthetic_whenExpression() {
     // Expected 0 errors of type StaticTypeWarningCode.UNDEFINED_GETTER, found 1 (29)
diff --git a/pkg/analyzer/test/generated/non_hint_code_kernel_test.dart b/pkg/analyzer/test/generated/non_hint_code_kernel_test.dart
index ede068d..8df0aa8 100644
--- a/pkg/analyzer/test/generated/non_hint_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/non_hint_code_kernel_test.dart
@@ -54,6 +54,13 @@
 
   @override
   @failingTest
+  test_propagatedFieldType() {
+    // Failed to resolve 1 nodes
+    return super.test_propagatedFieldType();
+  }
+
+  @override
+  @failingTest
   @notForDart2
   test_undefinedOperator_binaryExpression_inSubtype() async {
     await super.test_undefinedOperator_binaryExpression_inSubtype();
@@ -81,6 +88,20 @@
   }
 
   @override
+  @failingTest
+  test_unnecessaryCast_function() {
+    // NoSuchMethodError: The getter 'isBottom' was called on null.
+    return super.test_unnecessaryCast_function();
+  }
+
+  @override
+  @failingTest
+  test_unnecessaryCast_function2() {
+    // NoSuchMethodError: The getter 'isBottom' was called on null.
+    return super.test_unnecessaryCast_function2();
+  }
+
+  @override
   test_unnecessaryCast_generics() async {
     // dartbug.com/18953
     // Overridden because type inference now produces more information and there
diff --git a/pkg/analyzer/test/generated/static_type_analyzer_kernel_test.dart b/pkg/analyzer/test/generated/static_type_analyzer_kernel_test.dart
index a11639e..1ac4f2b 100644
--- a/pkg/analyzer/test/generated/static_type_analyzer_kernel_test.dart
+++ b/pkg/analyzer/test/generated/static_type_analyzer_kernel_test.dart
@@ -19,4 +19,11 @@
 
   @override
   bool get useCFE => true;
+
+  @override
+  @failingTest
+  test_staticMethods_classTypeParameters_genericMethod() {
+    // Bad state: Not found U in m<S>(S s) → void
+    return super.test_staticMethods_classTypeParameters_genericMethod();
+  }
 }
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_kernel_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_kernel_test.dart
index fd5c686..08a0800 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_kernel_test.dart
@@ -85,6 +85,13 @@
 
   @override
   @failingTest
+  test_forIn_declaredVariableRightType() {
+    // Failed to resolve 1 nodes
+    return super.test_forIn_declaredVariableRightType();
+  }
+
+  @override
+  @failingTest
   test_forIn_declaredVariableWrongType() async {
     // Expected 1 errors of type StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, found 0
     await super.test_forIn_declaredVariableWrongType();
@@ -92,6 +99,27 @@
 
   @override
   @failingTest
+  test_forIn_downcast() {
+    // Failed to resolve 1 nodes
+    return super.test_forIn_downcast();
+  }
+
+  @override
+  @failingTest
+  test_forIn_dynamicVariable() {
+    // Failed to resolve 1 nodes
+    return super.test_forIn_dynamicVariable();
+  }
+
+  @override
+  @failingTest
+  test_forIn_existingVariableRightType() {
+    // Failed to resolve 1 nodes
+    return super.test_forIn_existingVariableRightType();
+  }
+
+  @override
+  @failingTest
   test_forIn_existingVariableWrongType() async {
     // Expected 1 errors of type StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, found 0
     await super.test_forIn_existingVariableWrongType();
@@ -113,6 +141,20 @@
 
   @override
   @failingTest
+  test_forIn_typeBoundGood() {
+    // Failed to resolve 1 nodes
+    return super.test_forIn_typeBoundGood();
+  }
+
+  @override
+  @failingTest
+  test_forIn_upcast() {
+    // Failed to resolve 1 nodes
+    return super.test_forIn_upcast();
+  }
+
+  @override
+  @failingTest
   test_illegalAsyncGeneratorReturnType_function_nonStream() async {
     // Expected 1 errors of type StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, found 0
     await super.test_illegalAsyncGeneratorReturnType_function_nonStream();
@@ -490,6 +532,13 @@
 
   @override
   @failingTest
+  test_returnOfInvalidType_not_issued_for_valid_generic_return() {
+    // Failed to resolve 2 nodes
+    return super.test_returnOfInvalidType_not_issued_for_valid_generic_return();
+  }
+
+  @override
+  @failingTest
   test_returnOfInvalidType_void() async {
     // Expected 1 errors of type StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, found 0
     await super.test_returnOfInvalidType_void();
@@ -890,20 +939,6 @@
 
   @override
   @failingTest
-  test_wrongNumberOfTypeArguments_typeTest_tooFew() async {
-    // Bad state: Found 2 argument types for 1 type arguments
-    await super.test_wrongNumberOfTypeArguments_typeTest_tooFew();
-  }
-
-  @override
-  @failingTest
-  test_wrongNumberOfTypeArguments_typeTest_tooMany() async {
-    // Bad state: Found 1 argument types for 2 type arguments
-    await super.test_wrongNumberOfTypeArguments_typeTest_tooMany();
-  }
-
-  @override
-  @failingTest
   test_yield_async_to_basic_type() async {
     // Expected 1 errors of type StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, found 0;
     //          1 errors of type StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, found 0
diff --git a/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart b/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart
index f08be6a..804de7b 100644
--- a/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart
@@ -139,6 +139,27 @@
 
   @override
   @failingTest
+  test_argumentTypeNotAssignable_invocation_functionParameter_generic() {
+    return super
+        .test_argumentTypeNotAssignable_invocation_functionParameter_generic();
+  }
+
+  @override
+  @failingTest
+  test_argumentTypeNotAssignable_invocation_generic() {
+    // Failed to resolve 1 nodes
+    return super.test_argumentTypeNotAssignable_invocation_generic();
+  }
+
+  @override
+  @failingTest
+  test_argumentTypeNotAssignable_new_generic() {
+    // Failed to resolve 1 nodes
+    return super.test_argumentTypeNotAssignable_new_generic();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_assignmentToClass() async {
     return super.test_assignmentToClass();
@@ -798,6 +819,14 @@
 
   @override
   @failingTest
+  test_invalidMethodOverrideNormalParamType_superclass_interface() {
+    // Failed to resolve 2 nodes
+    return super
+        .test_invalidMethodOverrideNormalParamType_superclass_interface();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_invalidMethodOverrideNormalParamType_twoInterfaces_conflicting() async {
     return super
@@ -1242,6 +1271,13 @@
 
   @override
   @failingTest
+  test_notAType() {
+    // Bad state: No data for f at 18 in /test.dart
+    return super.test_notAType();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_notEnoughRequiredArguments() async {
     return super.test_notEnoughRequiredArguments();
@@ -1389,6 +1425,20 @@
 
   @override
   @failingTest
+  test_typeAnnotationDeferredClass_asExpression() {
+    // Bad state: No data for A at 68 in /lib2.dart
+    return super.test_typeAnnotationDeferredClass_asExpression();
+  }
+
+  @override
+  @failingTest
+  test_typeAnnotationDeferredClass_catchClause() {
+    // Bad state: No data for A at 76 in /lib2.dart
+    return super.test_typeAnnotationDeferredClass_catchClause();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_typeAnnotationDeferredClass_functionDeclaration_returnType() async {
     return super
@@ -1397,6 +1447,13 @@
 
   @override
   @failingTest
+  test_typeAnnotationDeferredClass_isExpression() {
+    // Bad state: No data for A at 77 in /lib2.dart
+    return super.test_typeAnnotationDeferredClass_isExpression();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_typeAnnotationDeferredClass_methodDeclaration_returnType() async {
     return super
@@ -1405,6 +1462,13 @@
 
   @override
   @failingTest
+  test_typeAnnotationDeferredClass_simpleFormalParameter() {
+    // Bad state: No data for A at 52 in /lib2.dart
+    return super.test_typeAnnotationDeferredClass_simpleFormalParameter();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_typeAnnotationDeferredClass_typeParameter_bound() async {
     return super.test_typeAnnotationDeferredClass_typeParameter_bound();
@@ -1412,6 +1476,13 @@
 
   @override
   @failingTest
+  test_typeParameterReferencedByStatic_methodBodyReference() {
+    // Failed to resolve 1 nodes
+    return super.test_typeParameterReferencedByStatic_methodBodyReference();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_typeParameterReferencedByStatic_methodParameter() async {
     return super.test_typeParameterReferencedByStatic_methodParameter();
diff --git a/pkg/analyzer/test/generated/strong_mode_kernel_test.dart b/pkg/analyzer/test/generated/strong_mode_kernel_test.dart
index 174f423..0e09713 100644
--- a/pkg/analyzer/test/generated/strong_mode_kernel_test.dart
+++ b/pkg/analyzer/test/generated/strong_mode_kernel_test.dart
@@ -37,6 +37,13 @@
 
   @override
   @failingTest
+  test_constrainedByBounds1() {
+    // Failed to resolve 1 nodes
+    return super.test_constrainedByBounds1();
+  }
+
+  @override
+  @failingTest
   test_constrainedByBounds2() async {
     // Expected: InterfaceTypeImpl:<int>
     await super.test_constrainedByBounds2();
@@ -51,6 +58,13 @@
 
   @override
   @failingTest
+  test_constrainedByBounds4() {
+    // Failed to resolve 1 nodes
+    return super.test_constrainedByBounds4();
+  }
+
+  @override
+  @failingTest
   test_constrainedByBounds5() async {
     // Bad state: Expected a type for 4 at 119; got one for kernel offset 118
     await super.test_constrainedByBounds5();
@@ -86,6 +100,90 @@
 
   @override
   @failingTest
+  test_futureOr_assignFromFuture() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_assignFromFuture();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_assignFromValue() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_assignFromValue();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_asyncExpressionBody() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_asyncExpressionBody();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_asyncReturn() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_asyncReturn();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_await() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_await();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards1() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards1();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards2() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards2();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards3() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards3();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards4() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards4();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards5() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards5();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards6() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards6();
+  }
+
+  @override
+  @failingTest
+  test_futureOr_downwards7() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards7();
+  }
+
+  @override
+  @failingTest
   test_futureOr_downwards8() async {
     // type 'BottomTypeImpl' is not a subtype of type 'InterfaceType' in type cast where
     await super.test_futureOr_downwards8();
@@ -93,6 +191,13 @@
 
   @override
   @failingTest
+  test_futureOr_downwards9() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_downwards9();
+  }
+
+  @override
+  @failingTest
   test_futureOr_methods2() async {
     // Expected 1 errors of type StaticTypeWarningCode.UNDEFINED_METHOD, found 0
     await super.test_futureOr_methods2();
@@ -135,6 +240,13 @@
 
   @override
   @failingTest
+  test_futureOr_upwards1() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOr_upwards1();
+  }
+
+  @override
+  @failingTest
   test_futureOr_upwards2() async {
     // Expected 1 errors of type StrongModeCode.STRONG_MODE_COULD_NOT_INFER, found 0
     await super.test_futureOr_upwards2();
@@ -142,6 +254,27 @@
 
   @override
   @failingTest
+  test_futureOrNull_no_return() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOrNull_no_return();
+  }
+
+  @override
+  @failingTest
+  test_futureOrNull_no_return_value() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOrNull_no_return_value();
+  }
+
+  @override
+  @failingTest
+  test_futureOrNull_return_null() {
+    // Failed to resolve 1 nodes
+    return super.test_futureOrNull_return_null();
+  }
+
+  @override
+  @failingTest
   test_generic_partial() async {
     // AnalysisException: Element mismatch in /test.dart at class A<T>
     await super.test_generic_partial();
@@ -198,6 +331,34 @@
 
   @override
   @failingTest
+  test_inference_simplePolymorphicRecursion_function() {
+    // Failed to resolve 4 nodes
+    return super.test_inference_simplePolymorphicRecursion_function();
+  }
+
+  @override
+  @failingTest
+  test_inference_simplePolymorphicRecursion_interface() {
+    // Failed to resolve 2 nodes
+    return super.test_inference_simplePolymorphicRecursion_interface();
+  }
+
+  @override
+  @failingTest
+  test_inference_simplePolymorphicRecursion_simple() {
+    // Failed to resolve 2 nodes
+    return super.test_inference_simplePolymorphicRecursion_simple();
+  }
+
+  @override
+  @failingTest
+  test_inferGenericInstantiation() {
+    // Failed to resolve 1 nodes
+    return super.test_inferGenericInstantiation();
+  }
+
+  @override
+  @failingTest
   test_inferGenericInstantiation2() async {
     // Expected 1 errors of type StrongModeCode.STRONG_MODE_COULD_NOT_INFER, found 0;
     //          1 errors of type StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, found 0
@@ -217,6 +378,13 @@
 
   @override
   @failingTest
+  test_partialTypes1() {
+    // Failed to resolve 2 nodes
+    return super.test_partialTypes1();
+  }
+
+  @override
+  @failingTest
   test_pinning_multipleConstraints1() async {
     // Expected 1 errors of type StrongModeCode.STRONG_MODE_INVALID_CAST_LITERAL, found 0
     await super.test_pinning_multipleConstraints1();
@@ -224,6 +392,13 @@
 
   @override
   @failingTest
+  test_pinning_multipleConstraints2() {
+    // Failed to resolve 1 nodes
+    return super.test_pinning_multipleConstraints2();
+  }
+
+  @override
+  @failingTest
   test_pinning_multipleConstraints3() async {
     // Expected 1 errors of type StrongModeCode.STRONG_MODE_INVALID_CAST_LITERAL, found 0
     await super.test_pinning_multipleConstraints3();
@@ -231,6 +406,34 @@
 
   @override
   @failingTest
+  test_pinning_multipleConstraints_contravariant1() {
+    // Failed to resolve 2 nodes
+    return super.test_pinning_multipleConstraints_contravariant1();
+  }
+
+  @override
+  @failingTest
+  test_pinning_multipleConstraints_contravariant2() {
+    // Failed to resolve 2 nodes
+    return super.test_pinning_multipleConstraints_contravariant2();
+  }
+
+  @override
+  @failingTest
+  test_pinning_multipleConstraints_contravariant3() {
+    // Failed to resolve 2 nodes
+    return super.test_pinning_multipleConstraints_contravariant3();
+  }
+
+  @override
+  @failingTest
+  test_pinning_multipleConstraints_contravariant4() {
+    // Failed to resolve 2 nodes
+    return super.test_pinning_multipleConstraints_contravariant4();
+  }
+
+  @override
+  @failingTest
   test_redirectedConstructor_named() {
     // Expected: 'A<T2, U2>'; Actual: 'A<T, U>'
     return super.test_redirectedConstructor_named();
@@ -251,6 +454,48 @@
     // TODO(brianwilkerson) Figure out why this test is flaky.
     fail('Flaky test');
   }
+
+  @override
+  @failingTest
+  test_returnType_variance1() {
+    // Failed to resolve 1 nodes
+    return super.test_returnType_variance1();
+  }
+
+  @override
+  @failingTest
+  test_returnType_variance2() {
+    // Failed to resolve 1 nodes
+    return super.test_returnType_variance2();
+  }
+
+  @override
+  @failingTest
+  test_returnType_variance3() {
+    // Failed to resolve 1 nodes
+    return super.test_returnType_variance3();
+  }
+
+  @override
+  @failingTest
+  test_returnType_variance4() {
+    // Failed to resolve 1 nodes
+    return super.test_returnType_variance4();
+  }
+
+  @override
+  @failingTest
+  test_returnType_variance5() {
+    // Failed to resolve 3 nodes
+    return super.test_returnType_variance5();
+  }
+
+  @override
+  @failingTest
+  test_returnType_variance6() {
+    // Failed to resolve 3 nodes
+    return super.test_returnType_variance6();
+  }
 }
 
 @reflectiveTest
@@ -266,13 +511,35 @@
   bool get useCFE => true;
 
   @override
+  @failingTest
   test_futureOr_promotion3() async {
-    // Test passes even though the overridden method fails.
+    // Failed to resolve 2 nodes
     await super.test_futureOr_promotion3();
   }
 
   @override
   @failingTest
+  test_futureOr_promotion4() {
+    // Failed to resolve 2 nodes
+    return super.test_futureOr_promotion4();
+  }
+
+  @override
+  @failingTest
+  test_genericFunction() {
+    // Failed to resolve 1 nodes
+    return super.test_genericFunction();
+  }
+
+  @override
+  @failingTest
+  test_genericFunction_bounds() {
+    // Failed to resolve 1 nodes
+    return super.test_genericFunction_bounds();
+  }
+
+  @override
+  @failingTest
   test_genericFunction_parameter() async {
     // Failed to resolve 1 nodes:
     await super.test_genericFunction_parameter();
@@ -280,6 +547,20 @@
 
   @override
   @failingTest
+  test_genericFunction_static() {
+    // Failed to resolve 1 nodes
+    return super.test_genericFunction_static();
+  }
+
+  @override
+  @failingTest
+  test_genericMethod() async {
+    // Failed to resolve 1 nodes
+    await super.test_genericMethod();
+  }
+
+  @override
+  @failingTest
   test_genericMethod_explicitTypeParams() async {
     // Bad state: Found 2 argument types for 1 type arguments
     await super.test_genericMethod_explicitTypeParams();
@@ -361,6 +642,13 @@
 
   @override
   @failingTest
+  test_genericMethod_nestedBound() async {
+    // Failed to resolve 1 nodes
+    await super.test_genericMethod_nestedBound();
+  }
+
+  @override
+  @failingTest
   test_genericMethod_nestedCapture() async {
     // Bad state: Found 2 argument types for 1 type arguments
     await super.test_genericMethod_nestedCapture();
@@ -368,6 +656,34 @@
 
   @override
   @failingTest
+  test_genericMethod_nestedFunctions() async {
+    // Failed to resolve 1 nodes
+    await super.test_genericMethod_nestedFunctions();
+  }
+
+  @override
+  @failingTest
+  test_genericMethod_override() async {
+    // Failed to resolve 2 nodes
+    await super.test_genericMethod_override();
+  }
+
+  @override
+  @failingTest
+  test_genericMethod_override_bounds() async {
+    // Failed to resolve 3 nodes
+    await super.test_genericMethod_override_bounds();
+  }
+
+  @override
+  @failingTest
+  test_genericMethod_override_differentContextsSameBounds() async {
+    // Failed to resolve 4 nodes
+    await super.test_genericMethod_override_differentContextsSameBounds();
+  }
+
+  @override
+  @failingTest
   test_genericMethod_override_invalidContravariantTypeParamBounds() async {
     // Expected 1 errors of type StrongModeCode.STRONG_MODE_INVALID_METHOD_OVERRIDE, found 0
     await super
@@ -384,6 +700,13 @@
 
   @override
   @failingTest
+  test_genericMethod_override_invalidReturnType() {
+    // Failed to resolve 2 nodes
+    return super.test_genericMethod_override_invalidReturnType();
+  }
+
+  @override
+  @failingTest
   test_genericMethod_override_invalidTypeParamCount() async {
     // Expected 1 errors of type StrongModeCode.STRONG_MODE_INVALID_METHOD_OVERRIDE, found 0
     await super.test_genericMethod_override_invalidTypeParamCount();
@@ -411,6 +734,27 @@
   }
 
   @override
+  @failingTest
+  test_instantiateToBounds_method_ok_referenceOther_before() {
+    // Failed to resolve 2 nodes
+    return super.test_instantiateToBounds_method_ok_referenceOther_before();
+  }
+
+  @override
+  @failingTest
+  test_instantiateToBounds_method_ok_simpleBounds() {
+    // Failed to resolve 1 nodes
+    return super.test_instantiateToBounds_method_ok_simpleBounds();
+  }
+
+  @override
+  @failingTest
+  test_issue32396() {
+    // Failed to resolve 1 nodes
+    return super.test_issue32396();
+  }
+
+  @override
   test_notInstantiatedBound_class_error_recursion_less_direct() async {
     return super.test_notInstantiatedBound_class_error_recursion_less_direct();
   }
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart
index c8bfccf..eb42be1 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart
@@ -37,6 +37,13 @@
 
   @override
   @failingTest
+  test_closure_generic() {
+    // Assertion error: 'element != null': is not true.
+    return super.test_closure_generic();
+  }
+
+  @override
+  @failingTest
   test_local_type_parameter_reference_function_named_parameter_type() {
     // Stack overflow
     return super
@@ -61,6 +68,14 @@
 
   @override
   @failingTest
+  test_local_type_parameter_reference_function_return_type() {
+    // type 'DynamicTypeImpl' is not a subtype of type 'TypeParameterType' in
+    // type cast
+    return super.test_local_type_parameter_reference_function_return_type();
+  }
+
+  @override
+  @failingTest
   @potentialAnalyzerProblem
   test_unresolved_assignment_left_indexed1_simple() async {
     await super.test_unresolved_assignment_left_indexed1_simple();
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
index bf1e233..db34b81 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
@@ -33,6 +33,8 @@
 
 final isUndefinedType = new TypeMatcher<UndefinedTypeImpl>();
 
+final isVoidType = new TypeMatcher<VoidTypeImpl>();
+
 /**
  * Integration tests for resolution.
  */
@@ -2419,11 +2421,7 @@
 
     TypeName typeName = statement.variables.type;
     expect(typeName.type, isUndefinedType);
-    if (useCFE) {
-      expect(typeName.typeArguments.arguments[0].type, isUndefinedType);
-    } else {
-      expect(typeName.typeArguments.arguments[0].type, typeProvider.intType);
-    }
+    expect(typeName.typeArguments.arguments[0].type, typeProvider.intType);
 
     VariableDeclaration vNode = statement.variables.variables[0];
     expect(vNode.name.staticType, isUndefinedType);
@@ -6984,6 +6982,23 @@
     }
   }
 
+  test_type_dynamic() async {
+    addTestFile('''
+main() {
+  dynamic d;
+}
+''');
+    await resolveTestFile();
+    var statements = _getMainStatements(result);
+    var variableDeclarationStatement =
+        statements[0] as VariableDeclarationStatement;
+    var type = variableDeclarationStatement.variables.type as TypeName;
+    expect(type.type, isDynamicType);
+    var typeName = type.name;
+    assertTypeDynamic(typeName);
+    expect(typeName.staticElement, same(typeProvider.dynamicType.element));
+  }
+
   test_type_functionTypeAlias() async {
     addTestFile(r'''
 typedef T F<T>(bool a);
@@ -7019,6 +7034,23 @@
     _assertTypeNameSimple(typeArguments[0], typeProvider.intType);
   }
 
+  test_type_void() async {
+    addTestFile('''
+main() {
+  void v;
+}
+''');
+    await resolveTestFile();
+    var statements = _getMainStatements(result);
+    var variableDeclarationStatement =
+        statements[0] as VariableDeclarationStatement;
+    var type = variableDeclarationStatement.variables.type as TypeName;
+    expect(type.type, isVoidType);
+    var typeName = type.name;
+    expect(typeName.staticType, isVoidType);
+    expect(typeName.staticElement, isNull);
+  }
+
   test_typeAnnotation_prefixed() async {
     var a = _p('/test/lib/a.dart');
     var b = _p('/test/lib/b.dart');
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index a3f705e..67ea0c0 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -2213,7 +2213,8 @@
       }
     }
     if (name is Generator) {
-      push(name.buildTypeWithBuiltArguments(arguments));
+      push(name.buildTypeWithBuiltArguments(arguments,
+          typeInferrer: _typeInferrer));
     } else if (name is TypeBuilder) {
       push(name.build(library));
     } else {
@@ -2257,6 +2258,8 @@
     DartType returnType = pop();
     List<TypeParameter> typeVariables = typeVariableBuildersToKernel(pop());
     FunctionType type = formals.toFunctionType(returnType, typeVariables);
+    // TODO(paulberry): communicate resolution information to the
+    // TypeInferenceListener (dartbug.com/33846).
     exitLocalScope();
     push(type);
   }
@@ -2264,7 +2267,9 @@
   @override
   void handleVoidKeyword(Token token) {
     debugEvent("VoidKeyword");
-    push(const VoidType());
+    var type = const VoidType();
+    _typeInferrer.voidType(token.offset, token, type);
+    push(type);
   }
 
   @override
diff --git a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
index e79923f..255f585 100644
--- a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
@@ -43,6 +43,8 @@
 
 import '../problems.dart' show unhandled, unsupported;
 
+import '../type_inference/type_inferrer.dart' show TypeInferrer;
+
 import 'constness.dart' show Constness;
 
 import 'expression_generator_helper.dart' show ExpressionGeneratorHelper;
@@ -69,6 +71,7 @@
         Name,
         Procedure,
         SyntheticExpressionJudgment,
+        TreeNode,
         TypeParameterType,
         UnresolvedVariableUnaryJudgment,
         VariableDeclaration;
@@ -77,11 +80,15 @@
     show
         AccessErrorBuilder,
         BuiltinTypeBuilder,
+        ClassBuilder,
         Declaration,
+        DynamicTypeBuilder,
         FunctionTypeAliasBuilder,
+        InvalidTypeBuilder,
         KernelClassBuilder,
         KernelFunctionTypeAliasBuilder,
-        KernelTypeVariableBuilder;
+        KernelTypeVariableBuilder,
+        TypeVariableBuilder;
 
 import 'kernel_expression_generator.dart'
     show IncompleteSendGenerator, SendAccessGenerator;
@@ -212,7 +219,7 @@
   }
 
   DartType buildTypeWithBuiltArguments(List<DartType> arguments,
-      {bool nonInstanceAccessIsError: false}) {
+      {bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
     helper.addProblem(templateNotAType.withArguments(token.lexeme),
         offsetForToken(token), lengthForToken(token));
     return const InvalidType();
@@ -503,7 +510,7 @@
 
   @override
   DartType buildTypeWithBuiltArguments(List<DartType> arguments,
-      {bool nonInstanceAccessIsError: false}) {
+      {bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
     helper.addProblem(
         templateDeferredTypeAnnotation.withArguments(
             suffixGenerator.buildTypeWithBuiltArguments(arguments,
@@ -555,7 +562,8 @@
 
   @override
   DartType buildTypeWithBuiltArguments(List<DartType> arguments,
-      {bool nonInstanceAccessIsError: false}) {
+      {bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
+    var declaration = this.declaration;
     if (arguments != null) {
       int expected = 0;
       if (declaration is KernelClassBuilder) {
@@ -601,6 +609,28 @@
       type =
           declaration.buildTypesWithBuiltArguments(helper.library, arguments);
     }
+    TreeNode declarationTarget;
+    Object declarationBinder;
+    if (declaration is KernelTypeVariableBuilder &&
+        declaration.binder != null) {
+      declarationBinder = declaration.binder;
+    } else if (declaration is DynamicTypeBuilder ||
+        declaration is InvalidTypeBuilder) {
+      // There's no target associated with these types, so we have to let
+      // the analyzer fill it in.
+    } else if (declaration is ClassBuilder ||
+        declaration is TypeVariableBuilder ||
+        declaration is FunctionTypeAliasBuilder) {
+      declarationTarget = declaration.target;
+    } else {
+      return unhandled(
+          "${declaration.runtimeType}",
+          "TypeUseGenerator.buildTypeWithBuiltArguments",
+          offsetForToken(token),
+          helper.uri);
+    }
+    typeInferrer?.storeTypeReference(
+        token.charOffset, declarationTarget, declarationBinder, type);
     if (type is TypeParameterType) {
       return helper.validatedTypeVariableUse(
           type, offsetForToken(token), nonInstanceAccessIsError);
@@ -1134,7 +1164,7 @@
 
   @override
   DartType buildTypeWithBuiltArguments(List<DartType> arguments,
-      {bool nonInstanceAccessIsError: false}) {
+      {bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
     Template<Message Function(Token, Token)> template = isUnresolved
         ? templateUnresolvedPrefixInTypeAnnotation
         : templateNotAPrefixInTypeAnnotation;
diff --git a/pkg/front_end/lib/src/fasta/kernel/factory.dart b/pkg/front_end/lib/src/fasta/kernel/factory.dart
index bd70e04..885c394 100644
--- a/pkg/front_end/lib/src/fasta/kernel/factory.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/factory.dart
@@ -434,6 +434,15 @@
   Expression typeLiteral(ExpressionJudgment judgment, int fileOffset,
       Node expressionType, DartType inferredType);
 
+  Type typeReference(
+      int fileOffset,
+      Token leftBracket,
+      List<Type> typeArguments,
+      Token rightBracket,
+      Node reference,
+      covariant Object binder,
+      DartType type);
+
   Object typeVariableDeclaration(
       covariant Object binder, TypeParameter typeParameter);
 
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart
index 484340e..36aaf0f 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart
@@ -24,6 +24,8 @@
 
 import '../problems.dart' show unhandled, unsupported;
 
+import '../type_inference/type_inferrer.dart' show TypeInferrer;
+
 import 'body_builder.dart' show noLocation;
 
 import 'constness.dart' show Constness;
@@ -1434,6 +1436,15 @@
       ..fileOffset = token.charOffset;
   }
 
+  DartType buildTypeWithBuiltArguments(List<DartType> arguments,
+      {bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
+    var type = super.buildTypeWithBuiltArguments(arguments,
+        nonInstanceAccessIsError: nonInstanceAccessIsError,
+        typeInferrer: typeInferrer);
+    typeInferrer.storeTypeReference(token.offset, null, null, type);
+    return type;
+  }
+
   @override
   void printOn(StringSink sink) {
     sink.write(", name: ");
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_factory.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_factory.dart
index 7c447c1..f474c5e 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_factory.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_factory.dart
@@ -2,6 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'package:front_end/src/fasta/kernel/kernel_type_variable_builder.dart';
 import 'package:front_end/src/scanner/token.dart' show Token;
 
 import 'package:kernel/ast.dart'
@@ -651,6 +652,16 @@
   }
 
   @override
+  void typeReference(
+      int fileOffset,
+      Token leftBracket,
+      List<void> typeArguments,
+      Token rightBracket,
+      Node reference,
+      covariant KernelTypeVariableBuilder binder,
+      DartType type) {}
+
+  @override
   TypeParameter typeVariableDeclaration(
       covariant KernelTypeVariableBuilder binder, TypeParameter typeParameter) {
     return typeParameter;
diff --git a/pkg/front_end/lib/src/fasta/kernel/toplevel_inference_factory.dart b/pkg/front_end/lib/src/fasta/kernel/toplevel_inference_factory.dart
index 077f51c..6aad140 100644
--- a/pkg/front_end/lib/src/fasta/kernel/toplevel_inference_factory.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/toplevel_inference_factory.dart
@@ -2,6 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'package:front_end/src/fasta/kernel/kernel_type_variable_builder.dart';
 import 'package:front_end/src/scanner/token.dart' show Token;
 
 import 'package:kernel/ast.dart'
@@ -494,6 +495,16 @@
       Node expressionType, DartType inferredType) {}
 
   @override
+  void typeReference(
+      int fileOffset,
+      Token leftBracket,
+      List<void> typeArguments,
+      Token rightBracket,
+      Node reference,
+      covariant void binder,
+      DartType type) {}
+
+  @override
   void typeVariableDeclaration(
       covariant void binder, TypeParameter typeParameter) {}
 
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inference_listener.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inference_listener.dart
index 4adf05f..4b2a6db 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inference_listener.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inference_listener.dart
@@ -441,6 +441,15 @@
   void typeLiteral(ExpressionJudgment judgment, Location location,
       Reference expressionType, DartType inferredType);
 
+  void typeReference(
+      Location location,
+      Token leftBracket,
+      List<void> typeArguments,
+      Token rightBracket,
+      Reference reference,
+      covariant Object binder,
+      DartType type);
+
   void typeVariableDeclaration(
       covariant Object binder, TypeParameter typeParameter);
 
@@ -458,6 +467,8 @@
   void variableGet(ExpressionJudgment judgment, Location location,
       bool isInCascade, covariant Object variableBinder, DartType inferredType);
 
+  void voidType(Location location, Token token, DartType type);
+
   void whileStatement(
       StatementJudgment judgment,
       Location location,
@@ -922,6 +933,10 @@
       DartType inferredType) {}
 
   @override
+  void typeReference(location, Token leftBracket, List<void> typeArguments,
+      Token rightBracket, reference, covariant void binder, DartType type) {}
+
+  @override
   void typeVariableDeclaration(
       covariant void binder, TypeParameter typeParameter) {}
 
@@ -943,6 +958,9 @@
       expressionVariable, DartType inferredType) {}
 
   @override
+  void voidType(location, Token token, DartType type) {}
+
+  @override
   void whileStatement(
       StatementJudgment judgment,
       location,
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
index 4709b46..64ee7d5 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
@@ -42,6 +42,7 @@
         SuperPropertySet,
         Supertype,
         ThisExpression,
+        TreeNode,
         TypeParameter,
         TypeParameterType,
         Typedef,
@@ -384,9 +385,14 @@
 
   void storePrefix(Token token, PrefixBuilder prefix);
 
+  void storeTypeReference(
+      int offset, TreeNode reference, Object binder, DartType type);
+
   void storeTypeUse(int offset, Node node);
 
   void typeVariableDeclaration(Object binder, TypeParameter typeParameter);
+
+  void voidType(int offset, Token token, DartType type);
 }
 
 /// Implementation of [TypeInferrer] which doesn't do any type inference.
@@ -452,10 +458,17 @@
   void storePrefix(Token token, PrefixBuilder prefix) {}
 
   @override
+  void storeTypeReference(
+      int offset, TreeNode reference, Object binder, DartType type) {}
+
+  @override
   void storeTypeUse(int offset, Node node) {}
 
   @override
   void typeVariableDeclaration(Object binder, TypeParameter typeParameter) {}
+
+  @override
+  void voidType(int offset, Token token, DartType type) {}
 }
 
 /// Derived class containing generic implementations of [TypeInferrer].
@@ -522,6 +535,7 @@
   /// inference.
   TypePromoter get typePromoter;
 
+  @override
   Object binderForTypeVariable(
       KernelTypeVariableBuilder builder, int fileOffset, String name) {
     return listener.binderForTypeVariable(builder, fileOffset, name);
@@ -1719,6 +1733,12 @@
   }
 
   @override
+  void storeTypeReference(
+      int offset, TreeNode reference, Object binder, DartType type) {
+    listener.typeReference(offset, null, null, null, reference, binder, type);
+  }
+
+  @override
   void storeTypeUse(int offset, Node node) {
     if (node is Class) {
       listener.storeClassReference(offset, node, node.rawType);
@@ -1741,6 +1761,11 @@
     return listener.typeVariableDeclaration(binder, typeParameter);
   }
 
+  @override
+  void voidType(int offset, Token token, DartType type) {
+    listener.voidType(offset, token, type);
+  }
+
   DartType wrapFutureOrType(DartType type) {
     if (type is InterfaceType &&
         identical(type.classNode, coreTypes.futureOrClass)) {