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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 2456803004: fixes #27586, prefer context type in generic inference (Closed)
Patch Set: wip Created 3 years, 11 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 2510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 TypeSystem ts = linker.typeSystem; 2521 TypeSystem ts = linker.typeSystem;
2522 if (rawMethodType != null) { 2522 if (rawMethodType != null) {
2523 if (rawMethodType.typeFormals.isNotEmpty && typeArguments.isNotEmpty) { 2523 if (rawMethodType.typeFormals.isNotEmpty && typeArguments.isNotEmpty) {
2524 Element methodElement = rawMethodType.element; 2524 Element methodElement = rawMethodType.element;
2525 if (methodElement is TypeParameterizedElement && 2525 if (methodElement is TypeParameterizedElement &&
2526 methodElement.typeParameters.length == typeArguments.length) { 2526 methodElement.typeParameters.length == typeArguments.length) {
2527 return rawMethodType.instantiate(typeArguments); 2527 return rawMethodType.instantiate(typeArguments);
2528 } 2528 }
2529 } else if (rawMethodType.typeFormals.isNotEmpty && 2529 } else if (rawMethodType.typeFormals.isNotEmpty &&
2530 ts is StrongTypeSystemImpl) { 2530 ts is StrongTypeSystemImpl) {
2531 List<DartType> paramTypes = <DartType>[]; 2531 List<ParameterElement> params = <ParameterElement>[];
2532 List<DartType> argTypes = <DartType>[]; 2532 List<DartType> argTypes = <DartType>[];
2533 // Add positional parameter and argument types. 2533 // Add positional parameter and argument types.
2534 for (int i = 0; i < numPositional; i++) { 2534 for (int i = 0; i < numPositional; i++) {
2535 ParameterElement parameter = rawMethodType.parameters[i]; 2535 ParameterElement parameter = rawMethodType.parameters[i];
2536 if (parameter != null) { 2536 if (parameter != null) {
2537 paramTypes.add(parameter.type); 2537 params.add(parameter);
2538 argTypes.add(positionalArgTypes[i]); 2538 argTypes.add(positionalArgTypes[i]);
2539 } 2539 }
2540 } 2540 }
2541 // Prepare named argument types map. 2541 // Prepare named argument types map.
2542 Map<String, DartType> namedArgTypes = <String, DartType>{}; 2542 Map<String, DartType> namedArgTypes = <String, DartType>{};
2543 for (int i = 0; i < numNamed; i++) { 2543 for (int i = 0; i < numNamed; i++) {
2544 String name = namedArgNames[i]; 2544 String name = namedArgNames[i];
2545 DartType type = namedArgTypeList[i]; 2545 DartType type = namedArgTypeList[i];
2546 namedArgTypes[name] = type; 2546 namedArgTypes[name] = type;
2547 } 2547 }
2548 // Add named parameter and argument types. 2548 // Add named parameter and argument types.
2549 Map<String, DartType> namedParameterTypes = 2549 Map<String, ParameterElement> namedParameters = new Map.fromIterable(
2550 rawMethodType.namedParameterTypes; 2550 rawMethodType.parameters
2551 .where((p) => p.parameterKind == ParameterKind.NAMED),
2552 key: (p) => p.name);
2551 namedArgTypes.forEach((String name, DartType argType) { 2553 namedArgTypes.forEach((String name, DartType argType) {
2552 DartType parameterType = namedParameterTypes[name]; 2554 ParameterElement parameter = namedParameters[name];
2553 if (parameterType != null) { 2555 if (parameter != null) {
2554 paramTypes.add(parameterType); 2556 params.add(parameter);
2555 argTypes.add(argType); 2557 argTypes.add(argType);
2556 } 2558 }
2557 }); 2559 });
2558 // Perform inference. 2560 // Perform inference.
2559 FunctionType inferred = ts.inferGenericFunctionCall(rawMethodType, 2561 FunctionType inferred = ts.inferGenericFunctionOrType(
2560 paramTypes, argTypes, rawMethodType.returnType, null); 2562 rawMethodType, params, argTypes, rawMethodType.returnType, null);
2561 return inferred; 2563 return inferred;
2562 } 2564 }
2563 } 2565 }
2564 // Not a generic function type, use the raw type. 2566 // Not a generic function type, use the raw type.
2565 return rawMethodType; 2567 return rawMethodType;
2566 } 2568 }
2567 2569
2568 DartType _leastUpperBound(DartType s, DartType t) { 2570 DartType _leastUpperBound(DartType s, DartType t) {
2569 return linker.typeSystem.getLeastUpperBound(s, t); 2571 return linker.typeSystem.getLeastUpperBound(s, t);
2570 } 2572 }
(...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after
4949 * there are no type parameters in scope. 4951 * there are no type parameters in scope.
4950 */ 4952 */
4951 TypeParameterizedElementMixin get _typeParameterContext; 4953 TypeParameterizedElementMixin get _typeParameterContext;
4952 4954
4953 @override 4955 @override
4954 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4956 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4955 4957
4956 @override 4958 @override
4957 String toString() => '$enclosingElement.$name'; 4959 String toString() => '$enclosingElement.$name';
4958 } 4960 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698