Issue 47302. Enable type parameters as potentially constant expressions.

Bug: https://github.com/dart-lang/sdk/issues/47302
Change-Id: I95d1b94efe5cc2877d37bc5ac615869233395189
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215014
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
index c2abc80..6f0eed7 100644
--- a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
+++ b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
@@ -244,6 +244,10 @@
     if (element is MethodElement && element.isStatic) {
       return;
     }
+    if (element is TypeParameterElement &&
+        featureSet.isEnabled(Feature.constructor_tearoffs)) {
+      return;
+    }
     nodes.add(node);
   }
 
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 e9e0a9a..0d881c1 100644
--- a/pkg/analyzer/test/src/dart/constant/potentially_constant_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/potentially_constant_test.dart
@@ -13,7 +13,6 @@
   defineReflectiveSuite(() {
     defineReflectiveTests(IsConstantTypeExpressionTest);
     defineReflectiveTests(PotentiallyConstantTest);
-    defineReflectiveTests(PotentiallyConstantWithoutNullSafetyTest);
   });
 }
 
@@ -216,6 +215,18 @@
 ''', () => _xInitializer());
   }
 
+  test_asExpression_typeParameter_29() async {
+    await _assertNotConst(r'''
+// @dart = 2.9
+const a = 0;
+class A<T> {
+  m() {
+    var x = a as T;
+  }
+}
+''', () => _xInitializer(), () => [findNode.namedType('T;')]);
+  }
+
   test_asExpression_typeParameter_nested() async {
     await _assertConst(r'''
 const a = 0;
@@ -518,6 +529,18 @@
 ''', () => _xInitializer());
   }
 
+  test_isExpression_typeParameter_29() async {
+    await _assertNotConst(r'''
+// @dart = 2.9
+const a = 0;
+class A<T> {
+  m() {
+    var x = a is T;
+  }
+}
+''', () => _xInitializer(), () => [findNode.namedType('T;')]);
+  }
+
   test_isExpression_typeParameter_nested() async {
     await _assertConst(r'''
 const a = 0;
@@ -1097,6 +1120,25 @@
 ''', () => _xInitializer());
   }
 
+  test_simpleIdentifier_typeParameter_class() async {
+    await _assertConst(r'''
+class A<T> {
+  final Object f;
+  A() : f = T;
+}
+''', () => findNode.simple('T;'));
+  }
+
+  test_simpleIdentifier_typeParameter_class_214() async {
+    await _assertNotConst(r'''
+// @dart = 2.14
+class A<T> {
+  final Object f;
+  A() : f = T;
+}
+''', () => findNode.simple('T;'), () => [findNode.simple('T;')]);
+  }
+
   test_spreadElement() async {
     await _assertConst(r'''
 const a = [0, 1, 2];
@@ -1162,46 +1204,3 @@
     return findNode.variableDeclaration('x = ').initializer!;
   }
 }
-
-@reflectiveTest
-class PotentiallyConstantWithoutNullSafetyTest extends PubPackageResolutionTest
-    with WithoutNullSafetyMixin {
-  test_asExpression_typeParameter() async {
-    await _assertNotConst(r'''
-const a = 0;
-class A<T> {
-  m() {
-    var x = a as T;
-  }
-}
-''', () => _xInitializer(), () => [findNode.namedType('T;')]);
-  }
-
-  test_isExpression_typeParameter() async {
-    await _assertNotConst(r'''
-const a = 0;
-class A<T> {
-  m() {
-    var x = a is T;
-  }
-}
-''', () => _xInitializer(), () => [findNode.namedType('T;')]);
-  }
-
-  _assertNotConst(String code, AstNode Function() getNode,
-      List<AstNode> Function() getNotConstList) async {
-    await resolveTestCode(code);
-    var node = getNode();
-    var notConstList = getNotPotentiallyConstants(
-      node,
-      featureSet: featureSet,
-    );
-
-    var expectedNotConst = getNotConstList();
-    expect(notConstList, unorderedEquals(expectedNotConst));
-  }
-
-  Expression _xInitializer() {
-    return findNode.variableDeclaration('x = ').initializer!;
-  }
-}