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

Unified Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 1967583002: Check bounds of type parameters of function type aliases. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/non_error_resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/error_verifier.dart
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 6d2f8b98276c829a7c62906b45c5325d8e7de2ea..29c6308dac3fbb3c120dfaf25ecfd290fbd31f8e 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -5225,40 +5225,45 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
if (type == null) {
return;
}
- // prepare ClassElement
+ // prepare type parameters
+ List<DartType> typeParameters = null;
+ List<TypeParameterElement> boundingElts = null;
+ List<DartType> typeArguments = null;
Element element = type.element;
if (element is ClassElement) {
Brian Wilkerson 2016/05/10 17:09:28 Both ClassElement and FunctionTypeAliasElement are
- // prepare type parameters
- List<DartType> typeParameters = element.type.typeArguments;
- List<TypeParameterElement> boundingElts = element.typeParameters;
- // iterate over each bounded type parameter and corresponding argument
- NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
- List<DartType> typeArguments = (type as InterfaceType).typeArguments;
- int loopThroughIndex =
- math.min(typeNameArgList.length, boundingElts.length);
-
- bool shouldSubstitute = typeArguments.length != 0 &&
- typeArguments.length == typeParameters.length;
- for (int i = 0; i < loopThroughIndex; i++) {
- TypeName argTypeName = typeNameArgList[i];
- DartType argType = argTypeName.type;
- DartType boundType = boundingElts[i].bound;
- if (argType != null && boundType != null) {
- if (shouldSubstitute) {
- boundType = boundType.substitute2(typeArguments, typeParameters);
- }
- if (!_typeSystem.isSubtypeOf(argType, boundType)) {
- ErrorCode errorCode;
- if (_isInConstInstanceCreation) {
- errorCode =
- CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
- } else {
- errorCode =
- StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
- }
- _errorReporter.reportTypeErrorForNode(
- errorCode, argTypeName, [argType, boundType]);
+ typeParameters = element.type.typeArguments;
+ boundingElts = element.typeParameters;
+ typeArguments = (type as InterfaceType).typeArguments;
+ } else if (element is FunctionTypeAliasElement) {
+ typeParameters = element.type.typeArguments;
+ boundingElts = element.typeParameters;
+ typeArguments = (type as FunctionType).typeArguments;
+ } else {
+ return;
+ }
+ // iterate over each bounded type parameter and corresponding argument
+ NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
+ int loopThroughIndex =
+ math.min(typeNameArgList.length, boundingElts.length);
+ bool shouldSubstitute = typeArguments.length != 0 &&
+ typeArguments.length == typeParameters.length;
+ for (int i = 0; i < loopThroughIndex; i++) {
+ TypeName argTypeName = typeNameArgList[i];
+ DartType argType = argTypeName.type;
+ DartType boundType = boundingElts[i].bound;
+ if (argType != null && boundType != null) {
+ if (shouldSubstitute) {
+ boundType = boundType.substitute2(typeArguments, typeParameters);
+ }
+ if (!_typeSystem.isSubtypeOf(argType, boundType)) {
+ ErrorCode errorCode;
+ if (_isInConstInstanceCreation) {
+ errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
+ } else {
+ errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
}
+ _errorReporter.reportTypeErrorForNode(
+ errorCode, argTypeName, [argType, boundType]);
}
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/non_error_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698