Skip to content

Commit 014cda4

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[cfe] Remove more nullability-based reasoning from shape checks
Closes #60076 Change-Id: Ia32f12be5399ae1a04243fb69a28541df98ede5b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408800 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent 2eec09d commit 014cda4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/front_end/test/type_inference/type_schema_environment_nnbd_test.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
19071907
expressionStaticType: "D<int>?",
19081908
checkTargetType: "E<int>",
19091909
typeParameters: "",
1910-
sufficiency: TypeShapeCheckSufficiency.insufficient);
1910+
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
19111911
checkTypeShapeCheckSufficiency(
19121912
expressionStaticType: "D<int>",
19131913
checkTargetType: "E<num>?",
@@ -1917,7 +1917,7 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
19171917
expressionStaticType: "D<int>?",
19181918
checkTargetType: "E<num>",
19191919
typeParameters: "",
1920-
sufficiency: TypeShapeCheckSufficiency.insufficient);
1920+
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
19211921
checkTypeShapeCheckSufficiency(
19221922
expressionStaticType: "D<int>",
19231923
checkTargetType: "E<dynamic>?",
@@ -1978,7 +1978,7 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
19781978
expressionStaticType: "F<int>?",
19791979
checkTargetType: "G<int, Object?>",
19801980
typeParameters: "",
1981-
sufficiency: TypeShapeCheckSufficiency.insufficient);
1981+
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
19821982
checkTypeShapeCheckSufficiency(
19831983
expressionStaticType: "F<int>",
19841984
checkTargetType: "G<num, Object?>?",
@@ -1988,6 +1988,11 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
19881988
expressionStaticType: "F<int>?",
19891989
checkTargetType: "G<num, Object?>",
19901990
typeParameters: "",
1991+
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
1992+
checkTypeShapeCheckSufficiency(
1993+
expressionStaticType: "D<int?>",
1994+
checkTargetType: "E<int>",
1995+
typeParameters: "",
19911996
sufficiency: TypeShapeCheckSufficiency.insufficient);
19921997
}
19931998

pkg/kernel/lib/type_environment.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ abstract class TypeEnvironment extends Types {
406406
// `E1`. The first type argument of `E2<num, dynamic>` is the same in all
407407
// such types, and the second type argument is the default type for the
408408
// second parameter of `E2`, so condition (2*) is satisfied. We conclude
409-
// that the shape check is sufficient in `e is E2<enum, dynamic>`.
409+
// that the shape check is sufficient in `e is E2<num, dynamic>`.
410410

411411
// First, we compute `B<Q1, ..., Qk>`, which is `A<T1, ..., Tn>` taken as
412412
// an instance of `B` in `e is/as A<T1, ..., Tn>`, where `B<S1, ..., Sk>`
@@ -469,7 +469,8 @@ abstract class TypeEnvironment extends Types {
469469
// Condition (2*) is satisfied. We need to check condition (1).
470470
return isSubtypeOf(
471471
expressionStaticType,
472-
testedAgainstTypeAsOperandClass,
472+
testedAgainstTypeAsOperandClass
473+
.withDeclaredNullability(Nullability.nullable),
473474
SubtypeCheckMode.withNullabilities)
474475
? TypeShapeCheckSufficiency.interfaceShape
475476
: TypeShapeCheckSufficiency.insufficient;

0 commit comments

Comments
 (0)