Skip to content

Commit d4f1b8f

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Deprecate TypeProvider.futureType/futureOrType
[email protected] Change-Id: Idde7d82b217b5921c0770d9b69f6934a1e1fc493 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117682 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 5464400 commit d4f1b8f

File tree

19 files changed

+77
-116
lines changed

19 files changed

+77
-116
lines changed

pkg/analysis_server/lib/src/services/refactoring/extract_method.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,29 +800,28 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
800800
// TODO(brianwilkerson) Determine whether this await is necessary.
801801
await null;
802802
TypeProvider typeProvider = await resolveResult.session.typeProvider;
803-
InterfaceType futureType = typeProvider.futureType;
804803
if (_selectionFunctionExpression != null) {
805804
variableType = '';
806805
returnType = '';
807806
} else if (_returnType == null) {
808807
variableType = null;
809808
if (_hasAwait) {
810-
returnType = _getTypeCode(futureType);
809+
returnType = _getTypeCode(typeProvider.futureDynamicType);
811810
} else {
812811
returnType = 'void';
813812
}
814813
} else if (_returnType.isDynamic) {
815814
variableType = '';
816815
if (_hasAwait) {
817-
returnType = _getTypeCode(futureType);
816+
returnType = _getTypeCode(typeProvider.futureDynamicType);
818817
} else {
819818
returnType = '';
820819
}
821820
} else {
822821
variableType = _getTypeCode(_returnType);
823822
if (_hasAwait) {
824-
if (_returnType.element != futureType.element) {
825-
returnType = _getTypeCode(futureType.instantiate([_returnType]));
823+
if (_returnType.element != typeProvider.futureElement) {
824+
returnType = _getTypeCode(typeProvider.futureType2(_returnType));
826825
}
827826
} else {
828827
returnType = variableType;

pkg/analysis_server/test/src/services/correction/fix/add_async_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main(Stream<String> names) {
3232
''');
3333
await assertHasFix('''
3434
import 'dart:async';
35-
Future main(Stream<String> names) async {
35+
Future<void> main(Stream<String> names) async {
3636
await for (String name in names) {
3737
print(name);
3838
}

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4781,9 +4781,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
47814781
}
47824782
}
47834783
if (!expectedType.isVoid && !fromType.isVoid) {
4784-
var checkWithType = (!_inAsync)
4785-
? fromType
4786-
: _typeProvider.futureType.instantiate(<DartType>[fromType]);
4784+
var checkWithType =
4785+
!_inAsync ? fromType : _typeProvider.futureType2(fromType);
47874786
if (_typeSystem.isAssignableTo(checkWithType, expectedType,
47884787
featureSet: _featureSet)) {
47894788
return;

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4731,7 +4731,7 @@ class ResolverVisitor extends ScopedVisitor {
47314731
if (type.isDartAsyncFutureOr) {
47324732
return type;
47334733
}
4734-
return typeProvider.futureOrType.instantiate([type]);
4734+
return typeProvider.futureOrType2(type);
47354735
}
47364736

47374737
/// If [contextType] is defined and is a subtype of `Iterable<Object>` and
@@ -6679,9 +6679,11 @@ abstract class TypeProvider {
66796679
InterfaceType get futureOrNullType;
66806680

66816681
/// Return the type representing the built-in type 'FutureOr'.
6682+
@Deprecated('Use futureOrType2() instead.')
66826683
InterfaceType get futureOrType;
66836684

66846685
/// Return the type representing the built-in type 'Future'.
6686+
@Deprecated('Use futureType2() instead.')
66856687
InterfaceType get futureType;
66866688

66876689
/// Return the type representing the built-in type 'int'.

pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,8 +1363,8 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
13631363
if (type.isDartAsyncFutureOr) {
13641364
type = (type as InterfaceType).typeArguments[0];
13651365
}
1366-
DartType futureType = _typeProvider.futureType
1367-
.instantiate(<DartType>[_typeSystem.flatten(type)]);
1366+
DartType futureType =
1367+
_typeProvider.futureType2(_typeSystem.flatten(type));
13681368
return _nonNullable(futureType);
13691369
} else {
13701370
return type;

pkg/analyzer/lib/src/generated/type_system.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,15 @@ class Dart2TypeSystem extends TypeSystem {
672672

673673
// given t1 is Future<A> | A, then:
674674
// (Future<A> | A) <: t2 iff Future<A> <: t2 and A <: t2.
675-
var t1Future = typeProvider.futureType.instantiate([t1TypeArg]);
675+
var t1Future = typeProvider.futureType2(t1TypeArg);
676676
return isSubtypeOf(t1Future, t2) && isSubtypeOf(t1TypeArg, t2);
677677
}
678678

679679
if (t2 is InterfaceTypeImpl && t2.isDartAsyncFutureOr) {
680680
// given t2 is Future<A> | A, then:
681681
// t1 <: (Future<A> | A) iff t1 <: Future<A> or t1 <: A
682682
var t2TypeArg = t2.typeArguments[0];
683-
var t2Future = typeProvider.futureType.instantiate([t2TypeArg]);
683+
var t2Future = typeProvider.futureType2(t2TypeArg);
684684
return isSubtypeOf(t1, t2Future) || isSubtypeOf(t1, t2TypeArg);
685685
}
686686

@@ -1533,14 +1533,14 @@ class GenericInferrer {
15331533
// GLB(FutureOr<A>, FutureOr<B>) == FutureOr<GLB(A, B)>
15341534
if (t2.isDartAsyncFutureOr) {
15351535
var t2TypeArg = t2.typeArguments[0];
1536-
return typeProvider.futureOrType
1537-
.instantiate([_getGreatestLowerBound(t1TypeArg, t2TypeArg)]);
1536+
return typeProvider
1537+
.futureOrType2(_getGreatestLowerBound(t1TypeArg, t2TypeArg));
15381538
}
15391539
// GLB(FutureOr<A>, Future<B>) == Future<GLB(A, B)>
15401540
if (t2.isDartAsyncFuture) {
15411541
var t2TypeArg = t2.typeArguments[0];
1542-
return typeProvider.futureType
1543-
.instantiate([_getGreatestLowerBound(t1TypeArg, t2TypeArg)]);
1542+
return typeProvider
1543+
.futureType2(_getGreatestLowerBound(t1TypeArg, t2TypeArg));
15441544
}
15451545
}
15461546
// GLB(FutureOr<A>, B) == GLB(A, B)
@@ -1719,15 +1719,15 @@ class GenericInferrer {
17191719

17201720
// given t1 is Future<A> | A, then:
17211721
// (Future<A> | A) <: t2 iff Future<A> <: t2 and A <: t2.
1722-
var t1Future = typeProvider.futureType.instantiate([t1TypeArg]);
1722+
var t1Future = typeProvider.futureType2(t1TypeArg);
17231723
return matchSubtype(t1Future, t2) && matchSubtype(t1TypeArg, t2);
17241724
}
17251725

17261726
if (t2 is InterfaceType && t2.isDartAsyncFutureOr) {
17271727
// given t2 is Future<A> | A, then:
17281728
// t1 <: (Future<A> | A) iff t1 <: Future<A> or t1 <: A
17291729
var t2TypeArg = t2.typeArguments[0];
1730-
var t2Future = typeProvider.futureType.instantiate([t2TypeArg]);
1730+
var t2Future = typeProvider.futureType2(t2TypeArg);
17311731

17321732
// First we try matching `t1 <: Future<A>`. If that succeeds *and*
17331733
// records at least one constraint, then we proceed using that constraint.

pkg/analyzer/lib/src/hint/sdk_constraint_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class SdkConstraintVerifier extends RecursiveAstVisitor<void> {
246246
}
247247
Element element = node.staticElement;
248248
if (checkFutureAndStream &&
249-
(element == _typeProvider.futureType.element ||
249+
(element == _typeProvider.futureElement ||
250250
element == _typeProvider.streamType.element)) {
251251
for (LibraryElement importedLibrary
252252
in _containingLibrary.importedLibraries) {

pkg/analyzer/lib/src/task/strong/checker.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,10 @@ class CodeChecker extends RecursiveAstVisitor {
10041004
expectedType = typeProvider.streamType;
10051005
} else {
10061006
// Future<T> -> FutureOr<T>
1007-
var typeArg = (type.element == typeProvider.futureType.element)
1007+
var typeArg = (type.element == typeProvider.futureElement)
10081008
? (type as InterfaceType).typeArguments[0]
10091009
: typeProvider.dynamicType;
1010-
return typeProvider.futureOrType.instantiate([typeArg]);
1010+
return typeProvider.futureOrType2(typeArg);
10111011
}
10121012
} else {
10131013
if (body.isGenerator) {
@@ -1128,7 +1128,7 @@ class CodeChecker extends RecursiveAstVisitor {
11281128
// In this case, we're more permissive than assignability.
11291129
if (to.isDartAsyncFutureOr) {
11301130
var to1 = (to as InterfaceType).typeArguments[0];
1131-
var to2 = typeProvider.futureType.instantiate([to1]);
1131+
var to2 = typeProvider.futureType2(to1);
11321132
return _needsImplicitCast(expr, to1, from: from) == true ||
11331133
_needsImplicitCast(expr, to2, from: from) == true;
11341134
}

pkg/analyzer/test/generated/elements_types_mixin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mixin ElementsTypesMixin {
103103
}
104104

105105
DartType futureType(DartType T) {
106-
var futureElement = typeProvider.futureType.element;
106+
var futureElement = typeProvider.futureElement;
107107
return interfaceType(futureElement, typeArguments: [T]);
108108
}
109109

pkg/analyzer/test/generated/static_type_analyzer_test.dart

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,16 @@ class StaticTypeAnalyzerTest extends EngineTestCase
351351
}
352352

353353
void test_flatten_related_types() {
354-
InterfaceType futureType = _typeProvider.futureType;
355354
InterfaceType intType = _typeProvider.intType;
356355
InterfaceType numType = _typeProvider.numType;
357356
// class A extends Future<int> implements Future<num> { ... }
358357
ClassElementImpl classA =
359-
ElementFactory.classElement('A', futureType.instantiate([intType]));
360-
classA.interfaces = <InterfaceType>[
361-
futureType.instantiate([numType])
362-
];
358+
ElementFactory.classElement('A', _typeProvider.futureType2(intType));
359+
classA.interfaces = <InterfaceType>[_typeProvider.futureType2(numType)];
363360
// class B extends Future<num> implements Future<int> { ... }
364361
ClassElementImpl classB =
365-
ElementFactory.classElement('B', futureType.instantiate([numType]));
366-
classB.interfaces = <InterfaceType>[
367-
futureType.instantiate([intType])
368-
];
362+
ElementFactory.classElement('B', _typeProvider.futureType2(numType));
363+
classB.interfaces = <InterfaceType>[_typeProvider.futureType2(intType)];
369364
// flatten(A) = flatten(B) = int, since int is more specific than num.
370365
expect(_flatten(interfaceType(classA)), intType);
371366
expect(_flatten(interfaceType(classB)), intType);
@@ -375,12 +370,11 @@ class StaticTypeAnalyzerTest extends EngineTestCase
375370
InterfaceType intType = _typeProvider.intType;
376371
DartType dynamicType = _typeProvider.dynamicType;
377372
InterfaceType futureDynamicType = _typeProvider.futureDynamicType;
378-
InterfaceType futureIntType =
379-
_typeProvider.futureType.instantiate([intType]);
373+
InterfaceType futureIntType = _typeProvider.futureType2(intType);
380374
InterfaceType futureFutureDynamicType =
381-
_typeProvider.futureType.instantiate([futureDynamicType]);
375+
_typeProvider.futureType2(futureDynamicType);
382376
InterfaceType futureFutureIntType =
383-
_typeProvider.futureType.instantiate([futureIntType]);
377+
_typeProvider.futureType2(futureIntType);
384378
// flatten(int) = int
385379
expect(_flatten(intType), intType);
386380
// flatten(dynamic) = dynamic
@@ -396,21 +390,16 @@ class StaticTypeAnalyzerTest extends EngineTestCase
396390
}
397391

398392
void test_flatten_unrelated_types() {
399-
InterfaceType futureType = _typeProvider.futureType;
400393
InterfaceType intType = _typeProvider.intType;
401394
InterfaceType stringType = _typeProvider.stringType;
402395
// class A extends Future<int> implements Future<String> { ... }
403396
ClassElementImpl classA =
404-
ElementFactory.classElement('A', futureType.instantiate([intType]));
405-
classA.interfaces = <InterfaceType>[
406-
futureType.instantiate([stringType])
407-
];
397+
ElementFactory.classElement('A', _typeProvider.futureType2(intType));
398+
classA.interfaces = <InterfaceType>[_typeProvider.futureType2(stringType)];
408399
// class B extends Future<String> implements Future<int> { ... }
409400
ClassElementImpl classB =
410-
ElementFactory.classElement('B', futureType.instantiate([stringType]));
411-
classB.interfaces = <InterfaceType>[
412-
futureType.instantiate([intType])
413-
];
401+
ElementFactory.classElement('B', _typeProvider.futureType2(stringType));
402+
classB.interfaces = <InterfaceType>[_typeProvider.futureType2(intType)];
414403
// flatten(A) = A and flatten(B) = B, since neither string nor int is more
415404
// specific than the other.
416405
expect(_flatten(interfaceType(classA)), interfaceType(classA));
@@ -463,10 +452,9 @@ class StaticTypeAnalyzerTest extends EngineTestCase
463452
void test_visitAwaitExpression_flattened() {
464453
// await e, where e has type Future<Future<int>>
465454
InterfaceType intType = _typeProvider.intType;
466-
InterfaceType futureIntType =
467-
_typeProvider.futureType.instantiate(<DartType>[intType]);
455+
InterfaceType futureIntType = _typeProvider.futureType2(intType);
468456
InterfaceType futureFutureIntType =
469-
_typeProvider.futureType.instantiate(<DartType>[futureIntType]);
457+
_typeProvider.futureType2(futureIntType);
470458
Expression node = AstTestFactory.awaitExpression(
471459
_resolvedVariable(futureFutureIntType, 'e'));
472460
expect(_analyze(node), same(futureIntType));
@@ -476,8 +464,7 @@ class StaticTypeAnalyzerTest extends EngineTestCase
476464
void test_visitAwaitExpression_simple() {
477465
// await e, where e has type Future<int>
478466
InterfaceType intType = _typeProvider.intType;
479-
InterfaceType futureIntType =
480-
_typeProvider.futureType.instantiate(<DartType>[intType]);
467+
InterfaceType futureIntType = _typeProvider.futureType2(intType);
481468
Expression node =
482469
AstTestFactory.awaitExpression(_resolvedVariable(futureIntType, 'e'));
483470
expect(_analyze(node), same(intType));
@@ -659,59 +646,42 @@ class StaticTypeAnalyzerTest extends EngineTestCase
659646
FunctionExpression node = _resolvedFunctionExpression(
660647
AstTestFactory.formalParameterList([]), body);
661648
DartType resultType = _analyze(node);
662-
_assertFunctionType(
663-
_typeProvider.futureType
664-
.instantiate(<DartType>[_typeProvider.dynamicType]),
665-
null,
666-
null,
667-
null,
668-
resultType);
649+
_assertFunctionType(_typeProvider.futureType2(_typeProvider.dynamicType),
650+
null, null, null, resultType);
669651
_listener.assertNoErrors();
670652
}
671653

672654
void test_visitFunctionExpression_async_expression_flatten() {
673655
// () async => e, where e has type Future<int>
674656
InterfaceType intType = _typeProvider.intType;
675-
InterfaceType futureIntType =
676-
_typeProvider.futureType.instantiate(<DartType>[intType]);
657+
InterfaceType futureIntType = _typeProvider.futureType2(intType);
677658
Expression expression = _resolvedVariable(futureIntType, 'e');
678659
ExpressionFunctionBody body =
679660
AstTestFactory.expressionFunctionBody(expression);
680661
body.keyword = TokenFactory.tokenFromString('async');
681662
FunctionExpression node = _resolvedFunctionExpression(
682663
AstTestFactory.formalParameterList([]), body);
683664
DartType resultType = _analyze(node);
684-
_assertFunctionType(
685-
_typeProvider.futureType
686-
.instantiate(<DartType>[_typeProvider.dynamicType]),
687-
null,
688-
null,
689-
null,
690-
resultType);
665+
_assertFunctionType(_typeProvider.futureType2(_typeProvider.dynamicType),
666+
null, null, null, resultType);
691667
_listener.assertNoErrors();
692668
}
693669

694670
void test_visitFunctionExpression_async_expression_flatten_twice() {
695671
// () async => e, where e has type Future<Future<int>>
696672
InterfaceType intType = _typeProvider.intType;
697-
InterfaceType futureIntType =
698-
_typeProvider.futureType.instantiate(<DartType>[intType]);
673+
InterfaceType futureIntType = _typeProvider.futureType2(intType);
699674
InterfaceType futureFutureIntType =
700-
_typeProvider.futureType.instantiate(<DartType>[futureIntType]);
675+
_typeProvider.futureType2(futureIntType);
701676
Expression expression = _resolvedVariable(futureFutureIntType, 'e');
702677
ExpressionFunctionBody body =
703678
AstTestFactory.expressionFunctionBody(expression);
704679
body.keyword = TokenFactory.tokenFromString('async');
705680
FunctionExpression node = _resolvedFunctionExpression(
706681
AstTestFactory.formalParameterList([]), body);
707682
DartType resultType = _analyze(node);
708-
_assertFunctionType(
709-
_typeProvider.futureType
710-
.instantiate(<DartType>[_typeProvider.dynamicType]),
711-
null,
712-
null,
713-
null,
714-
resultType);
683+
_assertFunctionType(_typeProvider.futureType2(_typeProvider.dynamicType),
684+
null, null, null, resultType);
715685
_listener.assertNoErrors();
716686
}
717687

0 commit comments

Comments
 (0)