@@ -2178,18 +2178,19 @@ class FlowModel<Type extends Object> {
21782178 FlowModel <Type > write <Variable extends Object >(
21792179 FlowModelHelper <Type > helper,
21802180 NonPromotionReason ? nonPromotionReason,
2181- Variable variable,
21822181 int variableKey,
21832182 Type writtenType,
21842183 SsaNode <Type > newSsaNode,
21852184 Operations <Variable , Type > operations,
2186- {bool promoteToTypeOfInterest = true }) {
2185+ {bool promoteToTypeOfInterest = true ,
2186+ required Type unpromotedType}) {
21872187 FlowModel <Type >? newModel;
21882188 VariableModel <Type >? infoForVar = variableInfo[variableKey];
21892189 if (infoForVar != null ) {
2190- VariableModel <Type > newInfoForVar = infoForVar.write (nonPromotionReason,
2191- variable, variableKey, writtenType, operations, newSsaNode,
2192- promoteToTypeOfInterest: promoteToTypeOfInterest);
2190+ VariableModel <Type > newInfoForVar = infoForVar.write (
2191+ nonPromotionReason, variableKey, writtenType, operations, newSsaNode,
2192+ promoteToTypeOfInterest: promoteToTypeOfInterest,
2193+ unpromotedType: unpromotedType);
21932194 if (! identical (newInfoForVar, infoForVar)) {
21942195 newModel = _updateVariableInfo (variableKey, newInfoForVar);
21952196 }
@@ -2863,12 +2864,12 @@ class VariableModel<Type extends Object> {
28632864 /// reason for any potential demotion.
28642865 VariableModel <Type > write <Variable extends Object >(
28652866 NonPromotionReason ? nonPromotionReason,
2866- Variable variable,
28672867 int variableKey,
28682868 Type writtenType,
28692869 Operations <Variable , Type > operations,
28702870 SsaNode <Type > newSsaNode,
2871- {required bool promoteToTypeOfInterest}) {
2871+ {required bool promoteToTypeOfInterest,
2872+ required Type unpromotedType}) {
28722873 if (writeCaptured) {
28732874 return new VariableModel <Type >(
28742875 promotedTypes: promotedTypes,
@@ -2882,10 +2883,9 @@ class VariableModel<Type extends Object> {
28822883 _demoteViaAssignment (writtenType, operations, nonPromotionReason);
28832884 List <Type >? newPromotedTypes = demotionResult.promotedTypes;
28842885
2885- Type declaredType = operations.variableType (variable);
28862886 if (promoteToTypeOfInterest) {
28872887 newPromotedTypes = _tryPromoteToTypeOfInterest (
2888- operations, declaredType , newPromotedTypes, writtenType);
2888+ operations, unpromotedType , newPromotedTypes, writtenType);
28892889 }
28902890 // TODO(paulberry): remove demotions from demotionResult.nonPromotionHistory
28912891 // that are no longer in effect due to re-promotion.
@@ -3949,6 +3949,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
39493949 {required bool isFinal,
39503950 required bool isLate,
39513951 required bool isImplicitlyTyped}) {
3952+ Type unpromotedType = operations.variableType (variable);
39523953 int variableKey = promotionKeyStore.keyForVariable (variable);
39533954 ExpressionInfo <Type >? expressionInfo;
39543955 if (isLate) {
@@ -3965,12 +3966,13 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
39653966 SsaNode <Type > newSsaNode = new SsaNode <Type >(
39663967 expressionInfo is _TrivialExpressionInfo ? null : expressionInfo);
39673968 _current = _current.write (
3968- this , null , variable, variableKey, matchedType, newSsaNode, operations,
3969- promoteToTypeOfInterest: ! isImplicitlyTyped && ! isFinal);
3969+ this , null , variableKey, matchedType, newSsaNode, operations,
3970+ promoteToTypeOfInterest: ! isImplicitlyTyped && ! isFinal,
3971+ unpromotedType: unpromotedType);
39703972 if (isImplicitlyTyped && operations.isTypeParameterType (matchedType)) {
39713973 _current = _current
3972- .tryPromoteForTypeCheck (
3973- this , _variableReference (variable, variableKey ), matchedType)
3974+ .tryPromoteForTypeCheck (this ,
3975+ _variableReference (variableKey, unpromotedType ), matchedType)
39743976 .ifTrue;
39753977 }
39763978 }
@@ -4436,11 +4438,12 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
44364438
44374439 @override
44384440 Type ? variableRead (Expression expression, Variable variable) {
4441+ Type unpromotedType = operations.variableType (variable);
44394442 int variableKey = promotionKeyStore.keyForVariable (variable);
44404443 VariableModel <Type > variableModel = _current._getInfo (variableKey);
44414444 Type ? promotedType = variableModel.promotedTypes? .last;
44424445 _storeExpressionReference (
4443- expression, _variableReference (variable, variableKey ));
4446+ expression, _variableReference (variableKey, unpromotedType ));
44444447 ExpressionInfo <Type >? expressionInfo = variableModel.ssaNode? .expressionInfo
44454448 ? .rebaseForward (operations, _current);
44464449 if (expressionInfo != null ) {
@@ -4505,6 +4508,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
45054508 @override
45064509 void write (Node node, Variable variable, Type writtenType,
45074510 Expression ? writtenExpression) {
4511+ Type unpromotedType = operations.variableType (variable);
45084512 int variableKey = promotionKeyStore.keyForVariable (variable);
45094513 ExpressionInfo <Type >? expressionInfo = writtenExpression == null
45104514 ? null
@@ -4514,11 +4518,11 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
45144518 _current = _current.write (
45154519 this ,
45164520 new DemoteViaExplicitWrite <Variable >(variable, node),
4517- variable,
45184521 variableKey,
45194522 writtenType,
45204523 newSsaNode,
4521- operations);
4524+ operations,
4525+ unpromotedType: unpromotedType);
45224526 }
45234527
45244528 @override
@@ -4775,9 +4779,9 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
47754779 isPromotable: false , isThisOrSuper: true );
47764780
47774781 ReferenceWithType <Type > _variableReference (
4778- Variable variable, int variableKey ) =>
4782+ int variableKey, Type unpromotedType ) =>
47794783 new ReferenceWithType <Type >(variableKey,
4780- promotedType (variable) ?? operations. variableType (variable) ,
4784+ _current. infoFor (variableKey).promotedTypes ? .last ?? unpromotedType ,
47814785 isPromotable: true , isThisOrSuper: false );
47824786}
47834787
0 commit comments