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

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 1968543002: Add 'ParameterizedType get type' to TypeParameterizedElement. (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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 type parameters
5229 List<DartType> typeParameters = null;
5230 List<TypeParameterElement> boundingElts = null;
5231 List<DartType> typeArguments = null;
5232 Element element = type.element; 5228 Element element = type.element;
5233 if (element is ClassElement) { 5229 if (element is TypeParameterizedElement) {
5234 typeParameters = element.type.typeArguments; 5230 // prepare type parameters
5235 boundingElts = element.typeParameters; 5231 List<TypeParameterElement> parameterElements = element.typeParameters;
5236 typeArguments = (type as InterfaceType).typeArguments; 5232 List<DartType> parameterTypes = element.type.typeArguments;
5237 } else if (element is FunctionTypeAliasElement) { 5233 List<DartType> arguments = (type as ParameterizedType).typeArguments;
5238 typeParameters = element.type.typeArguments; 5234 // iterate over each bounded type parameter and corresponding argument
5239 boundingElts = element.typeParameters; 5235 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
5240 typeArguments = (type as FunctionType).typeArguments; 5236 int loopThroughIndex =
5241 } else { 5237 math.min(typeNameArgList.length, parameterElements.length);
5242 return; 5238 bool shouldSubstitute = arguments.length != 0 &&
5243 } 5239 arguments.length == parameterTypes.length;
5244 // iterate over each bounded type parameter and corresponding argument 5240 for (int i = 0; i < loopThroughIndex; i++) {
5245 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; 5241 TypeName argTypeName = typeNameArgList[i];
5246 int loopThroughIndex = 5242 DartType argType = argTypeName.type;
5247 math.min(typeNameArgList.length, boundingElts.length); 5243 DartType boundType = parameterElements[i].bound;
5248 bool shouldSubstitute = typeArguments.length != 0 && 5244 if (argType != null && boundType != null) {
5249 typeArguments.length == typeParameters.length; 5245 if (shouldSubstitute) {
5250 for (int i = 0; i < loopThroughIndex; i++) { 5246 boundType = boundType.substitute2(arguments, parameterTypes);
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;
5264 } 5247 }
5265 _errorReporter.reportTypeErrorForNode( 5248 if (!_typeSystem.isSubtypeOf(argType, boundType)) {
5266 errorCode, argTypeName, [argType, boundType]); 5249 ErrorCode errorCode;
5250 if (_isInConstInstanceCreation) {
5251 errorCode =
5252 CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
5253 } else {
5254 errorCode =
5255 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
5256 }
5257 _errorReporter.reportTypeErrorForNode(
5258 errorCode, argTypeName, [argType, boundType]);
5259 }
5267 } 5260 }
5268 } 5261 }
5269 } 5262 }
5270 } 5263 }
5271 5264
5272 /** 5265 /**
5273 * Check whether the given type [name] is a type parameter being used to 5266 * Check whether the given type [name] is a type parameter being used to
5274 * define a static member. 5267 * define a static member.
5275 * 5268 *
5276 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]. 5269 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC].
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
6240 class _InvocationCollector extends RecursiveAstVisitor { 6233 class _InvocationCollector extends RecursiveAstVisitor {
6241 final List<String> superCalls = <String>[]; 6234 final List<String> superCalls = <String>[];
6242 6235
6243 @override 6236 @override
6244 visitMethodInvocation(MethodInvocation node) { 6237 visitMethodInvocation(MethodInvocation node) {
6245 if (node.target is SuperExpression) { 6238 if (node.target is SuperExpression) {
6246 superCalls.add(node.methodName.name); 6239 superCalls.add(node.methodName.name);
6247 } 6240 }
6248 } 6241 }
6249 } 6242 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698