@@ -40,7 +40,7 @@ abstract class ClosureContext {
40
40
/// the unknown type.
41
41
DartType get yieldContext;
42
42
43
- DartType ? get futureValueType ;
43
+ DartType ? get emittedValueType ;
44
44
45
45
factory ClosureContext (InferenceVisitorBase inferrer, AsyncMarker asyncMarker,
46
46
DartType returnContext, bool needToInferReturnType) {
@@ -142,6 +142,9 @@ class _SyncClosureContext implements ClosureContext {
142
142
@override
143
143
DartType get yieldContext => const UnknownType ();
144
144
145
+ @override
146
+ DartType ? get emittedValueType => null ;
147
+
145
148
final DartType _declaredReturnType;
146
149
147
150
final bool _needToInferReturnType;
@@ -161,9 +164,6 @@ class _SyncClosureContext implements ClosureContext {
161
164
/// being inferred.
162
165
List <DartType >? _returnExpressionTypes;
163
166
164
- @override
165
- DartType ? get futureValueType => null ;
166
-
167
167
_SyncClosureContext (this .inferrer, this ._returnContext,
168
168
this ._declaredReturnType, this ._needToInferReturnType) {
169
169
if (_needToInferReturnType) {
@@ -493,6 +493,9 @@ class _AsyncClosureContext implements ClosureContext {
493
493
@override
494
494
DartType get yieldContext => const UnknownType ();
495
495
496
+ @override
497
+ DartType ? emittedValueType;
498
+
496
499
final DartType _declaredReturnType;
497
500
498
501
final bool _needToInferReturnType;
@@ -512,15 +515,12 @@ class _AsyncClosureContext implements ClosureContext {
512
515
/// being inferred.
513
516
List <DartType >? _returnExpressionTypes;
514
517
515
- @override
516
- DartType ? futureValueType;
517
-
518
518
_AsyncClosureContext (
519
519
this .inferrer,
520
520
this ._returnContext,
521
521
this ._declaredReturnType,
522
522
this ._needToInferReturnType,
523
- this .futureValueType ) {
523
+ this .emittedValueType ) {
524
524
if (_needToInferReturnType) {
525
525
_returnStatements = [];
526
526
_returnExpressionTypes = [];
@@ -531,14 +531,14 @@ class _AsyncClosureContext implements ClosureContext {
531
531
DartType returnType, ReturnStatement statement, DartType expressionType) {
532
532
if (inferrer.isNonNullableByDefault) {
533
533
assert (
534
- futureValueType != null , "Future value type has not been computed." );
534
+ emittedValueType != null , "Future value type has not been computed." );
535
535
536
536
if (statement.expression == null ) {
537
537
// It is a compile-time error if s is `return;`, unless T_v is void,
538
538
// dynamic, or Null.
539
- if (futureValueType is VoidType ||
540
- futureValueType is DynamicType ||
541
- futureValueType is NullType ) {
539
+ if (emittedValueType is VoidType ||
540
+ emittedValueType is DynamicType ||
541
+ emittedValueType is NullType ) {
542
542
// Valid return;
543
543
} else {
544
544
statement.expression = inferrer.helper.wrapInProblem (
@@ -560,7 +560,7 @@ class _AsyncClosureContext implements ClosureContext {
560
560
561
561
DartType flattenedExpressionType =
562
562
inferrer.typeSchemaEnvironment.flatten (expressionType);
563
- if (futureValueType is VoidType &&
563
+ if (emittedValueType is VoidType &&
564
564
! (flattenedExpressionType is VoidType ||
565
565
flattenedExpressionType is DynamicType ||
566
566
flattenedExpressionType is NullType )) {
@@ -573,8 +573,8 @@ class _AsyncClosureContext implements ClosureContext {
573
573
statement.expression! .fileOffset,
574
574
noLength)
575
575
..parent = statement;
576
- } else if (! (futureValueType is VoidType ||
577
- futureValueType is DynamicType ) &&
576
+ } else if (! (emittedValueType is VoidType ||
577
+ emittedValueType is DynamicType ) &&
578
578
flattenedExpressionType is VoidType ) {
579
579
// It is a compile-time error if s is `return e;`, T_v is neither void
580
580
// nor dynamic, and flatten(S) is void.
@@ -588,13 +588,13 @@ class _AsyncClosureContext implements ClosureContext {
588
588
} else if (flattenedExpressionType is ! VoidType &&
589
589
! inferrer.typeSchemaEnvironment
590
590
.performNullabilityAwareSubtypeCheck (
591
- flattenedExpressionType, futureValueType ! )
591
+ flattenedExpressionType, emittedValueType ! )
592
592
.isSubtypeWhenUsingNullabilities ()) {
593
593
// It is a compile-time error if s is `return e;`, flatten(S) is not
594
594
// void, S is not assignable to T_v, and flatten(S) is not a subtype
595
595
// of T_v.
596
596
statement.expression = inferrer.ensureAssignable (
597
- futureValueType ! , expressionType, statement.expression! ,
597
+ emittedValueType ! , expressionType, statement.expression! ,
598
598
fileOffset: statement.expression! .fileOffset,
599
599
runtimeCheckedType:
600
600
inferrer.computeGreatestClosure2 (_returnContext),
@@ -831,10 +831,10 @@ class _AsyncClosureContext implements ClosureContext {
831
831
}
832
832
833
833
if (inferrer.isNonNullableByDefault) {
834
- futureValueType =
834
+ emittedValueType =
835
835
computeFutureValueType (inferrer.coreTypes, inferredType);
836
836
} else {
837
- futureValueType = inferrer.typeSchemaEnvironment.flatten (inferredType);
837
+ emittedValueType = inferrer.typeSchemaEnvironment.flatten (inferredType);
838
838
}
839
839
840
840
for (int i = 0 ; i < _returnStatements! .length; ++ i) {
@@ -915,21 +915,25 @@ class _SyncStarClosureContext implements ClosureContext {
915
915
@override
916
916
DartType get yieldContext => _yieldElementContext;
917
917
918
+ @override
919
+ DartType ? get emittedValueType => _emittedValueType;
920
+
918
921
final DartType _declaredReturnType;
919
922
923
+ DartType ? _emittedValueType;
924
+
920
925
final bool _needToInferReturnType;
921
926
922
927
/// A list of return expression types in functions whose return type is
923
928
/// being inferred.
924
929
List <DartType >? _yieldElementTypes;
925
930
926
- @override
927
- DartType ? get futureValueType => null ;
928
-
929
931
_SyncStarClosureContext (this .inferrer, this ._yieldElementContext,
930
932
this ._declaredReturnType, this ._needToInferReturnType) {
931
933
if (_needToInferReturnType) {
932
934
_yieldElementTypes = [];
935
+ } else {
936
+ _emittedValueType = inferrer.computeGreatestClosure (_yieldElementContext);
933
937
}
934
938
}
935
939
@@ -1009,8 +1013,13 @@ class _SyncStarClosureContext implements ClosureContext {
1009
1013
inferredType = inferrer.computeGreatestClosure2 (_declaredReturnType);
1010
1014
}
1011
1015
1012
- return demoteTypeInLibrary (inferredType,
1016
+ DartType demotedType = demoteTypeInLibrary (inferredType,
1013
1017
isNonNullableByDefault: inferrer.isNonNullableByDefault);
1018
+ _emittedValueType = inferrer.getTypeArgumentOf (
1019
+ inferrer.typeSchemaEnvironment.getUnionFreeType (demotedType,
1020
+ isNonNullableByDefault: inferrer.isNonNullableByDefault),
1021
+ inferrer.coreTypes.iterableClass);
1022
+ return demotedType;
1014
1023
}
1015
1024
1016
1025
@override
@@ -1050,21 +1059,25 @@ class _AsyncStarClosureContext implements ClosureContext {
1050
1059
@override
1051
1060
DartType get yieldContext => _yieldElementContext;
1052
1061
1062
+ @override
1063
+ DartType ? get emittedValueType => _emittedValueType;
1064
+
1053
1065
final DartType _declaredReturnType;
1054
1066
1067
+ DartType ? _emittedValueType;
1068
+
1055
1069
final bool _needToInferReturnType;
1056
1070
1057
1071
/// A list of return expression types in functions whose return type is
1058
1072
/// being inferred.
1059
1073
List <DartType >? _yieldElementTypes;
1060
1074
1061
- @override
1062
- DartType ? get futureValueType => null ;
1063
-
1064
1075
_AsyncStarClosureContext (this .inferrer, this ._yieldElementContext,
1065
1076
this ._declaredReturnType, this ._needToInferReturnType) {
1066
1077
if (_needToInferReturnType) {
1067
1078
_yieldElementTypes = [];
1079
+ } else {
1080
+ _emittedValueType = inferrer.computeGreatestClosure (_yieldElementContext);
1068
1081
}
1069
1082
}
1070
1083
@@ -1142,8 +1155,13 @@ class _AsyncStarClosureContext implements ClosureContext {
1142
1155
inferredType = inferrer.computeGreatestClosure2 (_declaredReturnType);
1143
1156
}
1144
1157
1145
- return demoteTypeInLibrary (inferredType,
1158
+ DartType demotedType = demoteTypeInLibrary (inferredType,
1146
1159
isNonNullableByDefault: inferrer.isNonNullableByDefault);
1160
+ _emittedValueType = inferrer.getTypeArgumentOf (
1161
+ inferrer.typeSchemaEnvironment.getUnionFreeType (demotedType,
1162
+ isNonNullableByDefault: inferrer.isNonNullableByDefault),
1163
+ inferrer.coreTypes.streamClass);
1164
+ return demotedType;
1147
1165
}
1148
1166
1149
1167
@override
0 commit comments