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

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1442883003: generic method type parameter inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 7c6becec92feec3e38b318e920735725e0697e53..863e65ad52cc935c7ce5d971a6421a77a034e9a9 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -203,23 +203,27 @@ class AnalysisContextFactory {
futureConstructor.factory = true;
futureElement.constructors = <ConstructorElement>[futureConstructor];
// Future then(onValue(T value), { Function onError });
- List<ParameterElement> parameters = <ParameterElement>[
- ElementFactory.requiredParameter2(
- "value", futureElement.typeParameters[0].type)
- ];
- FunctionElementImpl onValueFunction = new FunctionElementImpl.forNode(null);
- onValueFunction.synthetic = true;
- onValueFunction.parameters = parameters;
- onValueFunction.returnType = provider.dynamicType;
- onValueFunction.enclosingElement = futureElement;
- onValueFunction.type = new FunctionTypeImpl(onValueFunction);
- DartType futureDynamicType =
- futureElement.type.substitute4([provider.dynamicType]);
- MethodElement thenMethod = ElementFactory.methodElementWithParameters(
- futureElement, "then", futureDynamicType, [
- ElementFactory.requiredParameter2("onValue", onValueFunction.type),
+ TypeDefiningElement futureThenR = DynamicElementImpl.instance;
+ if (context.analysisOptions.strongMode) {
+ futureThenR = ElementFactory.typeParameterWithType('R');
+ }
+ FunctionElementImpl thenOnValue = ElementFactory.functionElement3(
+ 'onValue', futureThenR, [futureElement.typeParameters[0]], null);
+
+ DartType futureRType = futureElement.type.substitute4([futureThenR.type]);
+ MethodElementImpl thenMethod = ElementFactory.methodElementWithParameters(
+ futureElement, "then", futureRType, [
+ ElementFactory.requiredParameter2("onValue", thenOnValue.type),
ElementFactory.namedParameter2("onError", provider.functionType)
]);
+ if (!futureThenR.type.isDynamic) {
+ thenMethod.typeParameters = [futureThenR];
+ }
+ thenOnValue.enclosingElement = thenMethod;
+ thenOnValue.type = new FunctionTypeImpl(thenOnValue);
+ (thenMethod.parameters[0] as ParameterElementImpl).type = thenOnValue.type;
+ thenMethod.type = new FunctionTypeImpl(thenMethod);
+
futureElement.methods = <MethodElement>[thenMethod];
// Completer
ClassElementImpl completerElement =
@@ -340,11 +344,12 @@ class AnalysisContextFactory {
ClassElement.EMPTY_LIST);
TopLevelVariableElement ln10Element = ElementFactory
.topLevelVariableElement3("LN10", true, false, provider.doubleType);
- FunctionElement maxElement = ElementFactory.functionElement3(
- "max",
- provider.numType.element,
- <ClassElement>[provider.numType.element, provider.numType.element],
- ClassElement.EMPTY_LIST);
+ TypeParameterElement maxT =
+ ElementFactory.typeParameterWithType('T', provider.numType);
+ FunctionElementImpl maxElement = ElementFactory.functionElement3(
+ "max", maxT, [maxT, maxT], ClassElement.EMPTY_LIST);
+ maxElement.typeParameters = [maxT];
+ maxElement.type = new FunctionTypeImpl(maxElement);
TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
"PI", true, false, provider.doubleType);
ClassElementImpl randomElement = ElementFactory.classElement2("Random");

Powered by Google App Engine
This is Rietveld 408576698