Version 2.10.0-151.0.dev

Merge commit '04591ddfbcd92caf6d1155bf62906d47a559bdaa' into 'dev'
diff --git a/pkg/analyzer/lib/src/dart/element/type_demotion.dart b/pkg/analyzer/lib/src/dart/element/type_demotion.dart
index 064cb13..9421190 100644
--- a/pkg/analyzer/lib/src/dart/element/type_demotion.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_demotion.dart
@@ -2,24 +2,11 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE.md file.
 
-import 'package:analyzer/dart/element/element.dart';
 import 'package:analyzer/dart/element/nullability_suffix.dart';
 import 'package:analyzer/dart/element/type.dart';
 import 'package:analyzer/src/dart/element/replacement_visitor.dart';
 import 'package:analyzer/src/dart/element/type.dart';
-
-/// Returns [type] in which all promoted type variables have been replace with
-/// their unpromoted equivalents, and, if [library] is non-nullable by default,
-/// replaces all legacy types with their non-nullable equivalents.
-DartType demoteType(LibraryElement library, DartType type) {
-  if (library.isNonNullableByDefault) {
-    var visitor = const DemotionNonNullificationVisitor();
-    return type.accept(visitor) ?? type;
-  } else {
-    var visitor = const DemotionNonNullificationVisitor(nonNullifyTypes: false);
-    return type.accept(visitor) ?? type;
-  }
-}
+import 'package:meta/meta.dart';
 
 /// Visitor that replaces all promoted type variables the type variable itself
 /// and/or replaces all legacy types with non-nullable types.
@@ -30,8 +17,8 @@
   final bool nonNullifyTypes;
 
   const DemotionNonNullificationVisitor({
-    this.demoteTypeVariables = true,
-    this.nonNullifyTypes = true,
+    @required this.demoteTypeVariables,
+    @required this.nonNullifyTypes,
   }) : assert(demoteTypeVariables || nonNullifyTypes);
 
   @override
diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart
index bb8f69f..f088ab2 100644
--- a/pkg/analyzer/lib/src/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_system.dart
@@ -116,6 +116,25 @@
     return ft.parameters.any((p) => predicate(p.type));
   }
 
+  /// Returns [type] in which all promoted type variables have been replaced
+  /// with their unpromoted equivalents, and, if non-nullable by default,
+  /// replaces all legacy types with their non-nullable equivalents.
+  DartType demoteType(DartType type) {
+    if (isNonNullableByDefault) {
+      var visitor = const DemotionNonNullificationVisitor(
+        demoteTypeVariables: true,
+        nonNullifyTypes: true,
+      );
+      return type.accept(visitor) ?? type;
+    } else {
+      var visitor = const DemotionNonNullificationVisitor(
+        demoteTypeVariables: true,
+        nonNullifyTypes: false,
+      );
+      return type.accept(visitor) ?? type;
+    }
+  }
+
   /// Eliminates type variables from the context [type], replacing them with
   /// `Null` or `Object` as appropriate.
   ///
@@ -1184,9 +1203,10 @@
 
   /// Replace legacy types in [type] with non-nullable types.
   DartType nonNullifyLegacy(DartType type) {
-    if (isNonNullableByDefault && type != null) {
+    if (isNonNullableByDefault) {
       var visitor = const DemotionNonNullificationVisitor(
         demoteTypeVariables: false,
+        nonNullifyTypes: true,
       );
       return type.accept(visitor) ?? type;
     }
diff --git a/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart
index fb59963..20aae02 100644
--- a/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart
@@ -9,7 +9,6 @@
 import 'package:analyzer/src/dart/constant/utilities.dart';
 import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/type.dart';
-import 'package:analyzer/src/dart/element/type_demotion.dart';
 import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
 import 'package:analyzer/src/error/codes.dart';
 import 'package:analyzer/src/generated/resolver.dart';
@@ -81,10 +80,7 @@
         initializerType = DynamicTypeImpl.instance;
       }
 
-      var inferredType = demoteType(
-        _resolver.definingLibrary,
-        initializerType,
-      );
+      var inferredType = _resolver.typeSystem.demoteType(initializerType);
       element.type = inferredType;
     }
   }
diff --git a/tools/VERSION b/tools/VERSION
index e4f21fd..328d6ef 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
 MAJOR 2
 MINOR 10
 PATCH 0
-PRERELEASE 150
+PRERELEASE 151
 PRERELEASE_PATCH 0
\ No newline at end of file