Skip to content

Commit

Permalink
Version 3.4.0-211.0.dev
Browse files Browse the repository at this point in the history
Merge ffe61b7 into dev
  • Loading branch information
Dart CI committed Mar 7, 2024
2 parents bbf21a0 + ffe61b7 commit 4bc9735
Show file tree
Hide file tree
Showing 18 changed files with 463 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:kernel/ast.dart';
import 'package:kernel/type_environment.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

Expand Down Expand Up @@ -1637,6 +1638,93 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
checkUpperBound(type1: "E5<String>?", type2: "B", upperBound: "A<String>?");
}

void test_typeShapeCheckSufficiency() {
parseTestLibrary("""
class A<X>;
class B extends A<int>;
class C<Y> extends B;
class D<X>;
class E<Y> extends D<Y>;
class F<X>;
class G<Y, Z> extends F<Y>;
""");

checkTypeShapeCheckSufficiency(
expressionStaticType: "A<int>",
checkTargetType: "C<int>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.insufficient);
checkTypeShapeCheckSufficiency(
expressionStaticType: "A<int>",
checkTargetType: "C<String>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.insufficient);
checkTypeShapeCheckSufficiency(
expressionStaticType: "A<int>",
checkTargetType: "C<dynamic>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
checkTypeShapeCheckSufficiency(
expressionStaticType: "B",
checkTargetType: "C<int>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.insufficient);
checkTypeShapeCheckSufficiency(
expressionStaticType: "B",
checkTargetType: "C<Object?>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);

checkTypeShapeCheckSufficiency(
expressionStaticType: "D<int>",
checkTargetType: "E<int>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
checkTypeShapeCheckSufficiency(
expressionStaticType: "D<int>",
checkTargetType: "E<num>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
checkTypeShapeCheckSufficiency(
expressionStaticType: "D<int>",
checkTargetType: "E<dynamic>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
checkTypeShapeCheckSufficiency(
expressionStaticType: "D<num>",
checkTargetType: "E<int>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.insufficient);

checkTypeShapeCheckSufficiency(
expressionStaticType: "F<int>",
checkTargetType: "G<int, String>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.insufficient);
checkTypeShapeCheckSufficiency(
expressionStaticType: "F<int>",
checkTargetType: "G<num, String>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.insufficient);
checkTypeShapeCheckSufficiency(
expressionStaticType: "F<int>",
checkTargetType: "G<dynamic, Object?>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
checkTypeShapeCheckSufficiency(
expressionStaticType: "F<int>",
checkTargetType: "G<int, Object?>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
checkTypeShapeCheckSufficiency(
expressionStaticType: "F<int>",
checkTargetType: "G<num, Object?>",
typeParameters: "",
sufficiency: TypeShapeCheckSufficiency.interfaceShape);
}

void checkUpperBound(
{required String type1,
required String type2,
Expand All @@ -1660,4 +1748,22 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
parseType(upperBound));
});
}

@override
void checkTypeShapeCheckSufficiency(
{required String expressionStaticType,
required String checkTargetType,
required String typeParameters,
required TypeShapeCheckSufficiency sufficiency}) {
typeParserEnvironment.withStructuralParameters(typeParameters,
(List<StructuralParameter> structuralParameters) {
expect(
typeSchemaEnvironment.computeTypeShapeCheckSufficiency(
expressionStaticType: parseType(expressionStaticType),
checkTargetType: parseType(checkTargetType),
subtypeCheckMode: SubtypeCheckMode.withNullabilities) ==
sufficiency,
isTrue);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:kernel/ast.dart';
import 'package:kernel/type_environment.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

Expand Down Expand Up @@ -442,7 +443,7 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
parseTestLibrary("""
class A;
class B extends A;
class C<T extends Object*>;
class D<T extends Object*> extends C<T*>;
""");
Expand Down Expand Up @@ -557,4 +558,22 @@ class TypeSchemaEnvironmentTest extends TypeSchemaEnvironmentTestBase {
parseType(upperBound));
});
}

@override
void checkTypeShapeCheckSufficiency(
{required String expressionStaticType,
required String checkTargetType,
required String typeParameters,
required TypeShapeCheckSufficiency sufficiency}) {
typeParserEnvironment.withStructuralParameters(typeParameters,
(List<StructuralParameter> structuralParameters) {
expect(
typeSchemaEnvironment.computeTypeShapeCheckSufficiency(
expressionStaticType: parseType(expressionStaticType),
checkTargetType: parseType(checkTargetType),
subtypeCheckMode: SubtypeCheckMode.ignoringNullabilities) ==
sufficiency,
isTrue);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:kernel/ast.dart';
import 'package:kernel/core_types.dart';
import 'package:kernel/class_hierarchy.dart';
import 'package:kernel/testing/type_parser_environment.dart';
import 'package:kernel/type_environment.dart';
import 'package:test/test.dart';

abstract class TypeSchemaEnvironmentTestBase {
Expand Down Expand Up @@ -242,6 +243,12 @@ abstract class TypeSchemaEnvironmentTestBase {
});
}

void checkTypeShapeCheckSufficiency(
{required String expressionStaticType,
required String checkTargetType,
required String typeParameters,
required TypeShapeCheckSufficiency sufficiency});

/// Parses a string like "<: T <: S >: R" into a [TypeConstraint].
///
/// The [constraint] string is assumed to be a sequence of bounds added to the
Expand Down
2 changes: 2 additions & 0 deletions pkg/front_end/test/spell_checking_list_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ pv
q
q'i
qi
qk
qm
quad
qualify
Expand Down Expand Up @@ -1502,6 +1503,7 @@ right's
rightmost
ring
risk
rk
rn
rnystrom
robust
Expand Down
5 changes: 5 additions & 0 deletions pkg/front_end/test/spell_checking_list_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ below
beneficial
benefit
benign
besides
best
bets
better
Expand Down Expand Up @@ -1616,6 +1617,7 @@ instruction
instructions
instrumentation
instrumented
insufficient
int
intact
integer
Expand Down Expand Up @@ -2091,6 +2093,7 @@ observed
obtain
obtained
obvious
obviously
occur
occurred
occurrence
Expand Down Expand Up @@ -2560,6 +2563,7 @@ relations
relationship
relationships
relative
relaxed
release
releases
relevant
Expand Down Expand Up @@ -3000,6 +3004,7 @@ successively
succinct
such
suffice
sufficiency
sufficient
sufficiently
suffix
Expand Down
Loading

0 comments on commit 4bc9735

Please sign in to comment.