Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.error_verifier; | 5 library analyzer.src.generated.error_verifier; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 5207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5218 */ | 5218 */ |
| 5219 void _checkForTypeArgumentNotMatchingBounds(TypeName typeName) { | 5219 void _checkForTypeArgumentNotMatchingBounds(TypeName typeName) { |
| 5220 if (typeName.typeArguments == null) { | 5220 if (typeName.typeArguments == null) { |
| 5221 return; | 5221 return; |
| 5222 } | 5222 } |
| 5223 // prepare Type | 5223 // prepare Type |
| 5224 DartType type = typeName.type; | 5224 DartType type = typeName.type; |
| 5225 if (type == null) { | 5225 if (type == null) { |
| 5226 return; | 5226 return; |
| 5227 } | 5227 } |
| 5228 // prepare ClassElement | 5228 // prepare type parameters |
| 5229 List<DartType> typeParameters = null; | |
| 5230 List<TypeParameterElement> boundingElts = null; | |
| 5231 List<DartType> typeArguments = null; | |
| 5229 Element element = type.element; | 5232 Element element = type.element; |
| 5230 if (element is ClassElement) { | 5233 if (element is ClassElement) { |
|
Brian Wilkerson
2016/05/10 17:09:28
Both ClassElement and FunctionTypeAliasElement are
| |
| 5231 // prepare type parameters | 5234 typeParameters = element.type.typeArguments; |
| 5232 List<DartType> typeParameters = element.type.typeArguments; | 5235 boundingElts = element.typeParameters; |
| 5233 List<TypeParameterElement> boundingElts = element.typeParameters; | 5236 typeArguments = (type as InterfaceType).typeArguments; |
| 5234 // iterate over each bounded type parameter and corresponding argument | 5237 } else if (element is FunctionTypeAliasElement) { |
| 5235 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; | 5238 typeParameters = element.type.typeArguments; |
| 5236 List<DartType> typeArguments = (type as InterfaceType).typeArguments; | 5239 boundingElts = element.typeParameters; |
| 5237 int loopThroughIndex = | 5240 typeArguments = (type as FunctionType).typeArguments; |
| 5238 math.min(typeNameArgList.length, boundingElts.length); | 5241 } else { |
| 5239 | 5242 return; |
| 5240 bool shouldSubstitute = typeArguments.length != 0 && | 5243 } |
| 5241 typeArguments.length == typeParameters.length; | 5244 // iterate over each bounded type parameter and corresponding argument |
| 5242 for (int i = 0; i < loopThroughIndex; i++) { | 5245 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; |
| 5243 TypeName argTypeName = typeNameArgList[i]; | 5246 int loopThroughIndex = |
| 5244 DartType argType = argTypeName.type; | 5247 math.min(typeNameArgList.length, boundingElts.length); |
| 5245 DartType boundType = boundingElts[i].bound; | 5248 bool shouldSubstitute = typeArguments.length != 0 && |
| 5246 if (argType != null && boundType != null) { | 5249 typeArguments.length == typeParameters.length; |
| 5247 if (shouldSubstitute) { | 5250 for (int i = 0; i < loopThroughIndex; i++) { |
| 5248 boundType = boundType.substitute2(typeArguments, typeParameters); | 5251 TypeName argTypeName = typeNameArgList[i]; |
| 5252 DartType argType = argTypeName.type; | |
| 5253 DartType boundType = boundingElts[i].bound; | |
| 5254 if (argType != null && boundType != null) { | |
| 5255 if (shouldSubstitute) { | |
| 5256 boundType = boundType.substitute2(typeArguments, typeParameters); | |
| 5257 } | |
| 5258 if (!_typeSystem.isSubtypeOf(argType, boundType)) { | |
| 5259 ErrorCode errorCode; | |
| 5260 if (_isInConstInstanceCreation) { | |
| 5261 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | |
| 5262 } else { | |
| 5263 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | |
| 5249 } | 5264 } |
| 5250 if (!_typeSystem.isSubtypeOf(argType, boundType)) { | 5265 _errorReporter.reportTypeErrorForNode( |
| 5251 ErrorCode errorCode; | 5266 errorCode, argTypeName, [argType, boundType]); |
| 5252 if (_isInConstInstanceCreation) { | |
| 5253 errorCode = | |
| 5254 CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | |
| 5255 } else { | |
| 5256 errorCode = | |
| 5257 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | |
| 5258 } | |
| 5259 _errorReporter.reportTypeErrorForNode( | |
| 5260 errorCode, argTypeName, [argType, boundType]); | |
| 5261 } | |
| 5262 } | 5267 } |
| 5263 } | 5268 } |
| 5264 } | 5269 } |
| 5265 } | 5270 } |
| 5266 | 5271 |
| 5267 /** | 5272 /** |
| 5268 * Check whether the given type [name] is a type parameter being used to | 5273 * Check whether the given type [name] is a type parameter being used to |
| 5269 * define a static member. | 5274 * define a static member. |
| 5270 * | 5275 * |
| 5271 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]. | 5276 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]. |
| (...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6235 class _InvocationCollector extends RecursiveAstVisitor { | 6240 class _InvocationCollector extends RecursiveAstVisitor { |
| 6236 final List<String> superCalls = <String>[]; | 6241 final List<String> superCalls = <String>[]; |
| 6237 | 6242 |
| 6238 @override | 6243 @override |
| 6239 visitMethodInvocation(MethodInvocation node) { | 6244 visitMethodInvocation(MethodInvocation node) { |
| 6240 if (node.target is SuperExpression) { | 6245 if (node.target is SuperExpression) { |
| 6241 superCalls.add(node.methodName.name); | 6246 superCalls.add(node.methodName.name); |
| 6242 } | 6247 } |
| 6243 } | 6248 } |
| 6244 } | 6249 } |
| OLD | NEW |