Replace isNonNullableByDefault with FeatureSet in getNotPotentiallyConstants().

We need to check for more features now.

Bug: https://github.com/dart-lang/sdk/issues/47302
Change-Id: I601160aa4133e25695ead18d180f7efd2e410300
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215005
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
index 40a0feb..6adbb19 100644
--- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
+++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
@@ -73,8 +73,6 @@
               _currentLibrary.featureSet.isEnabled(Feature.non_nullable),
         );
 
-  bool get _isNonNullableByDefault => _currentLibrary.isNonNullableByDefault;
-
   @override
   void visitAnnotation(Annotation node) {
     super.visitAnnotation(node);
@@ -259,7 +257,7 @@
 
   @override
   void visitSwitchStatement(SwitchStatement node) {
-    if (_isNonNullableByDefault) {
+    if (_currentLibrary.isNonNullableByDefault) {
       _validateSwitchStatement_nullSafety(node);
     } else {
       _validateSwitchStatement_legacy(node);
@@ -424,7 +422,7 @@
   void _reportNotPotentialConstants(AstNode node) {
     var notPotentiallyConstants = getNotPotentiallyConstants(
       node,
-      isNonNullableByDefault: _isNonNullableByDefault,
+      featureSet: _currentLibrary.featureSet,
     );
     if (notPotentiallyConstants.isEmpty) return;
 
@@ -773,7 +771,7 @@
   bool _reportNotPotentialConstants(AstNode node) {
     var notPotentiallyConstants = getNotPotentiallyConstants(
       node,
-      isNonNullableByDefault: verifier._isNonNullableByDefault,
+      featureSet: verifier._currentLibrary.featureSet,
     );
     if (notPotentiallyConstants.isEmpty) return true;
 
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 26fdf2b..e26da9a 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -1760,7 +1760,7 @@
   void _reportNotPotentialConstants(AstNode node) {
     var notPotentiallyConstants = getNotPotentiallyConstants(
       node,
-      isNonNullableByDefault: _isNonNullableByDefault,
+      featureSet: _library.featureSet,
     );
     if (notPotentiallyConstants.isEmpty) return;
 
diff --git a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
index 3b37d629..c2abc80 100644
--- a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
+++ b/pkg/analyzer/lib/src/dart/constant/potentially_constant.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:analyzer/dart/analysis/features.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/ast/token.dart';
 import 'package:analyzer/dart/element/element.dart';
@@ -17,10 +18,10 @@
 /// Return the list of nodes that are not potentially constant.
 List<AstNode> getNotPotentiallyConstants(
   AstNode node, {
-  required bool isNonNullableByDefault,
+  required FeatureSet featureSet,
 }) {
   var collector = _Collector(
-    isNonNullableByDefault: isNonNullableByDefault,
+    featureSet: featureSet,
   );
   collector.collect(node);
   return collector.nodes;
@@ -50,10 +51,10 @@
 }
 
 class _Collector {
-  final bool isNonNullableByDefault;
+  final FeatureSet featureSet;
   final List<AstNode> nodes = [];
 
-  _Collector({required this.isNonNullableByDefault});
+  _Collector({required this.featureSet});
 
   void collect(AstNode node) {
     if (node is BooleanLiteral ||
@@ -139,7 +140,7 @@
     }
 
     if (node is AsExpression) {
-      if (isNonNullableByDefault) {
+      if (featureSet.isEnabled(Feature.non_nullable)) {
         if (!isPotentiallyConstantTypeExpression(node.type)) {
           nodes.add(node.type);
         }
@@ -153,7 +154,7 @@
     }
 
     if (node is IsExpression) {
-      if (isNonNullableByDefault) {
+      if (featureSet.isEnabled(Feature.non_nullable)) {
         if (!isPotentiallyConstantTypeExpression(node.type)) {
           nodes.add(node.type);
         }
diff --git a/pkg/analyzer/test/src/dart/constant/potentially_constant_test.dart b/pkg/analyzer/test/src/dart/constant/potentially_constant_test.dart
index 6184eb4..e9e0a9a 100644
--- a/pkg/analyzer/test/src/dart/constant/potentially_constant_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/potentially_constant_test.dart
@@ -1140,7 +1140,7 @@
     var node = getNode();
     var notConstList = getNotPotentiallyConstants(
       node,
-      isNonNullableByDefault: typeSystem.isNonNullableByDefault,
+      featureSet: featureSet,
     );
     expect(notConstList, isEmpty);
   }
@@ -1151,7 +1151,7 @@
     var node = getNode();
     var notConstList = getNotPotentiallyConstants(
       node,
-      isNonNullableByDefault: typeSystem.isNonNullableByDefault,
+      featureSet: featureSet,
     );
 
     var expectedNotConst = getNotConstList();
@@ -1194,7 +1194,7 @@
     var node = getNode();
     var notConstList = getNotPotentiallyConstants(
       node,
-      isNonNullableByDefault: typeSystem.isNonNullableByDefault,
+      featureSet: featureSet,
     );
 
     var expectedNotConst = getNotConstList();
diff --git a/pkg/analyzer/test/src/dart/resolution/resolution.dart b/pkg/analyzer/test/src/dart/resolution/resolution.dart
index 9daf620..b4e1b0b 100644
--- a/pkg/analyzer/test/src/dart/resolution/resolution.dart
+++ b/pkg/analyzer/test/src/dart/resolution/resolution.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:analyzer/dart/analysis/features.dart';
 import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/element/element.dart';
@@ -47,6 +48,8 @@
 
   bool get enableUnusedLocalVariable => false;
 
+  FeatureSet get featureSet => result.libraryElement.featureSet;
+
   ClassElement get futureElement => typeProvider.futureElement;
 
   /// TODO(scheglov) https://github.com/dart-lang/sdk/issues/43608