Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart

Issue 2863833002: Implement inferGenericFunctionOrType in front_end. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart
diff --git a/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart b/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart
index 5475095e3e7ac0fe223da4159b5422a3949d4b72..6bc40ac5cf9b0e01d0461e17776f38b3557e0a8b 100644
--- a/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart
+++ b/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart
@@ -259,6 +259,47 @@ class TypeSchemaEnvironmentTest {
expect(env.getGreatestLowerBound(A, B), same(bottomType));
}
+ void test_inferGenericFunctionOrType() {
+ var env = _makeEnv();
+ {
+ // Test an instantiation of [1, 2.0] with no context. This should infer
+ // as List<?> during downwards inference.
+ var typesFromDownwardsInference = <DartType>[null];
+ TypeParameterType T = listClass.thisType.typeArguments[0];
+ expect(
+ env.inferGenericFunctionOrType([T.parameter], listClass.thisType, [],
+ [], null, typesFromDownwardsInference,
+ downwards: true),
+ _list(unknownType));
+ // And upwards inference should refine it to List<num>.
+ expect(
+ env.inferGenericFunctionOrType([T.parameter], listClass.thisType,
+ [T, T], [intType, doubleType], null, typesFromDownwardsInference),
+ _list(numType));
+ }
+ {
+ // Test an instantiation of [1, 2.0] with a context of List<Object>. This
+ // should infer as List<Object> during downwards inference.
+ var typesFromDownwardsInference = <DartType>[null];
+ TypeParameterType T = listClass.thisType.typeArguments[0];
+ expect(
+ env.inferGenericFunctionOrType([T.parameter], listClass.thisType, [],
+ [], _list(objectType), typesFromDownwardsInference,
+ downwards: true),
+ _list(objectType));
+ // And upwards inference should preserve the type.
+ expect(
+ env.inferGenericFunctionOrType(
+ [T.parameter],
+ listClass.thisType,
+ [T, T],
+ [intType, doubleType],
+ _list(objectType),
+ typesFromDownwardsInference),
+ _list(objectType));
+ }
+ }
+
void test_inferTypeFromConstraints_applyBound() {
// class A<T extends num> {}
var T = new TypeParameter('T', numType);

Powered by Google App Engine
This is Rietveld 408576698