| Index: pkg/analyzer/test/generated/type_system_test.dart
|
| diff --git a/pkg/analyzer/test/generated/type_system_test.dart b/pkg/analyzer/test/generated/type_system_test.dart
|
| index 0f6ea84d5fb39b618214677aebec14eb79bb185a..19336bd76ca1e8eb2830febdbdf67491c2aa025b 100644
|
| --- a/pkg/analyzer/test/generated/type_system_test.dart
|
| +++ b/pkg/analyzer/test/generated/type_system_test.dart
|
| @@ -6,14 +6,21 @@
|
|
|
| library analyzer.test.generated.type_system_test;
|
|
|
| +import 'package:analyzer/analyzer.dart' show ErrorReporter, StrongModeCode;
|
| +import 'package:analyzer/dart/ast/standard_ast_factory.dart' show astFactory;
|
| +import 'package:analyzer/dart/ast/token.dart' show Keyword;
|
| import 'package:analyzer/dart/element/element.dart';
|
| import 'package:analyzer/dart/element/type.dart';
|
| +import 'package:analyzer/src/dart/ast/token.dart' show KeywordToken;
|
| import 'package:analyzer/src/dart/element/element.dart';
|
| import 'package:analyzer/src/dart/element/type.dart';
|
| import 'package:analyzer/src/generated/engine.dart';
|
| import 'package:analyzer/src/generated/resolver.dart';
|
| +import 'package:analyzer/src/generated/source.dart'
|
| + show NonExistingSource, UriKind;
|
| import 'package:analyzer/src/generated/testing/element_factory.dart';
|
| import 'package:analyzer/src/generated/testing/test_type_provider.dart';
|
| +import 'package:path/path.dart' show toUri;
|
| import 'package:test/test.dart';
|
| import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
| @@ -973,7 +980,8 @@ class StrongGenericFunctionInferenceTest {
|
| expect(_inferCall(clone, [foo.type, foo.type]), [foo.type]);
|
|
|
| // Something invalid...
|
| - expect(_inferCall(clone, [stringType, numType]), null);
|
| + expect(_inferCall(clone, [stringType, numType], expectError: true),
|
| + [objectType]);
|
| }
|
|
|
| void test_genericCastFunction() {
|
| @@ -1073,21 +1081,22 @@ class StrongGenericFunctionInferenceTest {
|
| // <T>() -> T
|
| var t = TypeBuilder.variable('T');
|
| var f = TypeBuilder.function(types: [t], required: [], result: t);
|
| - expect(_inferCall(f, [], stringType), [stringType]);
|
| + expect(_inferCall(f, [], returnType: stringType), [stringType]);
|
| }
|
|
|
| void test_returnTypeWithBoundFromContext() {
|
| // <T extends num>() -> T
|
| var t = TypeBuilder.variable('T', bound: numType);
|
| var f = TypeBuilder.function(types: [t], required: [], result: t);
|
| - expect(_inferCall(f, [], doubleType), [doubleType]);
|
| + expect(_inferCall(f, [], returnType: doubleType), [doubleType]);
|
| }
|
|
|
| void test_returnTypeWithBoundFromInvalidContext() {
|
| // <T extends num>() -> T
|
| var t = TypeBuilder.variable('T', bound: numType);
|
| var f = TypeBuilder.function(types: [t], required: [], result: t);
|
| - expect(_inferCall(f, [], stringType), null);
|
| + expect(_inferCall(f, [], returnType: stringType, expectError: true),
|
| + [stringType]);
|
| }
|
|
|
| void test_unifyParametersToFunctionParam() {
|
| @@ -1100,11 +1109,14 @@ class StrongGenericFunctionInferenceTest {
|
| TypeBuilder.function(required: [t], result: dynamicType)
|
| ], result: t);
|
| expect(
|
| - _inferCall(cast, [
|
| - TypeBuilder.function(required: [intType], result: dynamicType),
|
| - TypeBuilder.function(required: [doubleType], result: dynamicType)
|
| - ]),
|
| - null);
|
| + _inferCall(
|
| + cast,
|
| + [
|
| + TypeBuilder.function(required: [intType], result: dynamicType),
|
| + TypeBuilder.function(required: [doubleType], result: dynamicType)
|
| + ],
|
| + expectError: true),
|
| + [dynamicType]);
|
| }
|
|
|
| void test_unusedReturnTypeIsDynamic() {
|
| @@ -1122,13 +1134,26 @@ class StrongGenericFunctionInferenceTest {
|
| }
|
|
|
| List<DartType> _inferCall(FunctionTypeImpl ft, List<DartType> arguments,
|
| - [DartType returnType]) {
|
| - FunctionType inferred = typeSystem.inferGenericFunctionCall(
|
| - ft,
|
| - ft.parameters.map((p) => p.type).toList(),
|
| - arguments,
|
| - ft.returnType,
|
| - returnType);
|
| + {DartType returnType, bool expectError: false}) {
|
| + var listener = new RecordingErrorListener();
|
| +
|
| + var reporter = new ErrorReporter(
|
| + listener,
|
| + new NonExistingSource(
|
| + '/test.dart', toUri('/test.dart'), UriKind.FILE_URI));
|
| +
|
| + FunctionType inferred = typeSystem.inferGenericFunctionOrType(
|
| + ft, ft.parameters, arguments, ft.returnType, returnType,
|
| + errorReporter: reporter,
|
| + errorNode: astFactory.nullLiteral(new KeywordToken(Keyword.NULL, 0)));
|
| +
|
| + if (expectError) {
|
| + expect(listener.errors.map((e) => e.errorCode).toList(),
|
| + [StrongModeCode.COULD_NOT_INFER],
|
| + reason: 'expected exactly 1 could not infer error.');
|
| + } else {
|
| + expect(listener.errors, isEmpty, reason: 'did not expect any errors.');
|
| + }
|
| return inferred?.typeArguments;
|
| }
|
| }
|
|
|