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

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

Issue 1514683002: fix #25183, add support to ErrorVerifier for generic methods (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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 engine.resolver.error_verifier; 5 library engine.resolver.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/src/generated/static_type_analyzer.dart'; 10 import 'package:analyzer/src/generated/static_type_analyzer.dart';
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 String executableElementName = executableElement.name; 1340 String executableElementName = executableElement.name;
1341 FunctionType overridingFT = executableElement.type; 1341 FunctionType overridingFT = executableElement.type;
1342 FunctionType overriddenFT = overriddenExecutable.type; 1342 FunctionType overriddenFT = overriddenExecutable.type;
1343 InterfaceType enclosingType = _enclosingClass.type; 1343 InterfaceType enclosingType = _enclosingClass.type;
1344 overriddenFT = _inheritanceManager 1344 overriddenFT = _inheritanceManager
1345 .substituteTypeArgumentsInMemberFromInheritance( 1345 .substituteTypeArgumentsInMemberFromInheritance(
1346 overriddenFT, executableElementName, enclosingType); 1346 overriddenFT, executableElementName, enclosingType);
1347 if (overridingFT == null || overriddenFT == null) { 1347 if (overridingFT == null || overriddenFT == null) {
1348 return false; 1348 return false;
1349 } 1349 }
1350
1351 // Handle generic function type parameters.
1352 // TODO(jmesserly): generic methods should work without strong mode,
1353 // however "instantiateToBounds" is currently on StrongTypeSystemImpl.
Leaf 2015/12/09 22:02:29 The non-strong mode semantics might be different,
Jennifer Messerly 2015/12/09 22:37:41 Done. Fixed this TODO by implementing the right lo
1354 TypeSystem ts = _typeSystem;
1355 if (ts is StrongTypeSystemImpl) {
1356 // TODO(jmesserly): this duplicates some code in isSubtypeOf and most of
1357 // _isGenericFunctionSubtypeOf. Ideally, we'd let TypeSystem produce
1358 // an error message once it's ready to "return false".
Leaf 2015/12/09 22:02:29 Yeah, this seems like it would work out well. May
Jennifer Messerly 2015/12/09 22:37:41 Sounds good. I don't want to try that restructure
1359 if (!overridingFT.boundTypeParameters.isEmpty) {
1360 if (overriddenFT.boundTypeParameters.isEmpty) {
1361 overriddenFT = ts.instantiateToBounds(overriddenFT);
1362 } else {
1363 List<TypeParameterElement> params1 = overridingFT.boundTypeParameters;
1364 List<TypeParameterElement> params2 = overriddenFT.boundTypeParameters;
1365 int count = params1.length;
1366 if (params2.length != count) {
1367 _errorReporter.reportErrorForNode(
1368 StaticWarningCode.INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS,
1369 errorNameTarget, [
1370 count,
1371 params2.length,
1372 overriddenExecutable.enclosingElement.displayName
1373 ]);
1374 return true;
1375 }
1376 // We build up a substitution matching up the type parameters
1377 // from the two types, {variablesFresh/variables1} and
1378 // {variablesFresh/variables2}
1379 List<DartType> variables1 = new List<DartType>();
1380 List<DartType> variables2 = new List<DartType>();
1381 List<DartType> variablesFresh = new List<DartType>();
1382 for (int i = 0; i < count; i++) {
1383 TypeParameterElement p1 = params1[i];
1384 TypeParameterElement p2 = params2[i];
1385 TypeParameterElementImpl pFresh =
1386 new TypeParameterElementImpl(p2.name, -1);
1387
1388 DartType variable1 = p1.type;
1389 DartType variable2 = p2.type;
1390 DartType variableFresh = new TypeParameterTypeImpl(pFresh);
1391
1392 variables1.add(variable1);
1393 variables2.add(variable2);
1394 variablesFresh.add(variableFresh);
1395 DartType bound1 = p1.bound ?? DynamicTypeImpl.instance;
1396 DartType bound2 = p2.bound ?? DynamicTypeImpl.instance;
1397 bound1 = bound1.substitute2(variablesFresh, variables1);
1398 bound2 = bound2.substitute2(variablesFresh, variables2);
1399 pFresh.bound = bound2;
1400 if (!ts.isSubtypeOf(bound2, bound1)) {
1401 _errorReporter.reportErrorForNode(
1402 StaticWarningCode.INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND ,
1403 errorNameTarget, [
1404 p1.displayName,
1405 p1.bound,
1406 p2.displayName,
1407 p2.bound,
1408 overriddenExecutable.enclosingElement.displayName
1409 ]);
1410 return true;
1411 }
1412 }
1413 // Proceed with the rest of the checks, using instantiated types.
Leaf 2015/12/09 22:02:29 The error messages that we get from the rest of th
Jennifer Messerly 2015/12/09 22:37:41 Eeeep good catch. I've switch it to use the "overr
1414 overridingFT = overridingFT.instantiate(variablesFresh);
1415 overriddenFT = overriddenFT.instantiate(variablesFresh);
1416 }
1417 }
1418 }
1419
1350 DartType overridingFTReturnType = overridingFT.returnType; 1420 DartType overridingFTReturnType = overridingFT.returnType;
1351 DartType overriddenFTReturnType = overriddenFT.returnType; 1421 DartType overriddenFTReturnType = overriddenFT.returnType;
1352 List<DartType> overridingNormalPT = overridingFT.normalParameterTypes; 1422 List<DartType> overridingNormalPT = overridingFT.normalParameterTypes;
1353 List<DartType> overriddenNormalPT = overriddenFT.normalParameterTypes; 1423 List<DartType> overriddenNormalPT = overriddenFT.normalParameterTypes;
1354 List<DartType> overridingPositionalPT = overridingFT.optionalParameterTypes; 1424 List<DartType> overridingPositionalPT = overridingFT.optionalParameterTypes;
1355 List<DartType> overriddenPositionalPT = overriddenFT.optionalParameterTypes; 1425 List<DartType> overriddenPositionalPT = overriddenFT.optionalParameterTypes;
1356 Map<String, DartType> overridingNamedPT = overridingFT.namedParameterTypes; 1426 Map<String, DartType> overridingNamedPT = overridingFT.namedParameterTypes;
1357 Map<String, DartType> overriddenNamedPT = overriddenFT.namedParameterTypes; 1427 Map<String, DartType> overriddenNamedPT = overriddenFT.namedParameterTypes;
1358 // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and 1428 // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and
1359 // CTEC.INVALID_OVERRIDE_NAMED 1429 // CTEC.INVALID_OVERRIDE_NAMED
(...skipping 4750 matching lines...) Expand 10 before | Expand all | Expand 10 after
6110 toCheck.add(type.element); 6180 toCheck.add(type.element);
6111 // type arguments 6181 // type arguments
6112 if (type is InterfaceType) { 6182 if (type is InterfaceType) {
6113 InterfaceType interfaceType = type; 6183 InterfaceType interfaceType = type;
6114 for (DartType typeArgument in interfaceType.typeArguments) { 6184 for (DartType typeArgument in interfaceType.typeArguments) {
6115 _addTypeToCheck(typeArgument); 6185 _addTypeToCheck(typeArgument);
6116 } 6186 }
6117 } 6187 }
6118 } 6188 }
6119 } 6189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698