[cfe] Remove more nullability-based reasoning from shape checks

Closes https://github.com/dart-lang/sdk/issues/60076

Change-Id: Ia32f12be5399ae1a04243fb69a28541df98ede5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408800
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
diff --git a/pkg/front_end/test/type_inference/type_schema_environment_nnbd_test.dart b/pkg/front_end/test/type_inference/type_schema_environment_nnbd_test.dart
index ea6db7f..7be475a 100644
--- a/pkg/front_end/test/type_inference/type_schema_environment_nnbd_test.dart
+++ b/pkg/front_end/test/type_inference/type_schema_environment_nnbd_test.dart
@@ -1907,7 +1907,7 @@
         expressionStaticType: "D<int>?",
         checkTargetType: "E<int>",
         typeParameters: "",
-        sufficiency: TypeShapeCheckSufficiency.insufficient);
+        sufficiency: TypeShapeCheckSufficiency.interfaceShape);
     checkTypeShapeCheckSufficiency(
         expressionStaticType: "D<int>",
         checkTargetType: "E<num>?",
@@ -1917,7 +1917,7 @@
         expressionStaticType: "D<int>?",
         checkTargetType: "E<num>",
         typeParameters: "",
-        sufficiency: TypeShapeCheckSufficiency.insufficient);
+        sufficiency: TypeShapeCheckSufficiency.interfaceShape);
     checkTypeShapeCheckSufficiency(
         expressionStaticType: "D<int>",
         checkTargetType: "E<dynamic>?",
@@ -1978,7 +1978,7 @@
         expressionStaticType: "F<int>?",
         checkTargetType: "G<int, Object?>",
         typeParameters: "",
-        sufficiency: TypeShapeCheckSufficiency.insufficient);
+        sufficiency: TypeShapeCheckSufficiency.interfaceShape);
     checkTypeShapeCheckSufficiency(
         expressionStaticType: "F<int>",
         checkTargetType: "G<num, Object?>?",
@@ -1988,6 +1988,11 @@
         expressionStaticType: "F<int>?",
         checkTargetType: "G<num, Object?>",
         typeParameters: "",
+        sufficiency: TypeShapeCheckSufficiency.interfaceShape);
+    checkTypeShapeCheckSufficiency(
+        expressionStaticType: "D<int?>",
+        checkTargetType: "E<int>",
+        typeParameters: "",
         sufficiency: TypeShapeCheckSufficiency.insufficient);
   }
 
diff --git a/pkg/kernel/lib/type_environment.dart b/pkg/kernel/lib/type_environment.dart
index b1e22ba..ea53592 100644
--- a/pkg/kernel/lib/type_environment.dart
+++ b/pkg/kernel/lib/type_environment.dart
@@ -406,7 +406,7 @@
       // `E1`. The first type argument of `E2<num, dynamic>` is the same in all
       // such types, and the second type argument is the default type for the
       // second parameter of `E2`, so condition (2*) is satisfied. We conclude
-      // that the shape check is sufficient in `e is E2<enum, dynamic>`.
+      // that the shape check is sufficient in `e is E2<num, dynamic>`.
 
       // First, we compute `B<Q1, ..., Qk>`, which is `A<T1, ..., Tn>` taken as
       // an instance of `B` in `e is/as A<T1, ..., Tn>`, where `B<S1, ..., Sk>`
@@ -469,7 +469,8 @@
           // Condition (2*) is satisfied. We need to check condition (1).
           return isSubtypeOf(
                   expressionStaticType,
-                  testedAgainstTypeAsOperandClass,
+                  testedAgainstTypeAsOperandClass
+                      .withDeclaredNullability(Nullability.nullable),
                   SubtypeCheckMode.withNullabilities)
               ? TypeShapeCheckSufficiency.interfaceShape
               : TypeShapeCheckSufficiency.insufficient;