@@ -666,7 +666,8 @@ class InferenceVisitor
666
666
read,
667
667
readType,
668
668
node.binaryName,
669
- node.rhs);
669
+ node.rhs,
670
+ null );
670
671
671
672
Expression binary = binaryResult.expression;
672
673
DartType binaryType = binaryResult.inferredType;
@@ -2906,7 +2907,8 @@ class InferenceVisitor
2906
2907
read,
2907
2908
readType,
2908
2909
node.binaryName,
2909
- node.rhs);
2910
+ node.rhs,
2911
+ null );
2910
2912
DartType binaryType = binaryResult.inferredType;
2911
2913
2912
2914
Expression binary =
@@ -3999,7 +4001,8 @@ class InferenceVisitor
3999
4001
Expression left,
4000
4002
DartType leftType,
4001
4003
Name binaryName,
4002
- Expression right) {
4004
+ Expression right,
4005
+ Map <DartType , NonPromotionReason > Function () whyNotPromoted) {
4003
4006
assert (binaryName != equalsName);
4004
4007
4005
4008
ObjectAccessTarget binaryTarget = inferrer.findInterfaceMember (
@@ -4203,14 +4206,19 @@ class InferenceVisitor
4203
4206
}
4204
4207
4205
4208
if (! inferrer.isTopLevel && binaryTarget.isNullable) {
4209
+ List <LocatedMessage > context = inferrer.getWhyNotPromotedContext (
4210
+ whyNotPromoted? .call (),
4211
+ binary,
4212
+ (type) => ! type.isPotentiallyNullable);
4206
4213
return new ExpressionInferenceResult (
4207
4214
binaryType,
4208
4215
inferrer.helper.wrapInProblem (
4209
4216
binary,
4210
4217
templateNullableOperatorCallError.withArguments (
4211
4218
binaryName.text, leftType, inferrer.isNonNullableByDefault),
4212
4219
binary.fileOffset,
4213
- binaryName.text.length));
4220
+ binaryName.text.length,
4221
+ context: context));
4214
4222
}
4215
4223
return new ExpressionInferenceResult (binaryType, binary);
4216
4224
}
@@ -4220,8 +4228,12 @@ class InferenceVisitor
4220
4228
///
4221
4229
/// [fileOffset] is used as the file offset for created nodes.
4222
4230
/// [expressionType] is the already inferred type of the [expression] .
4223
- ExpressionInferenceResult _computeUnaryExpression (int fileOffset,
4224
- Expression expression, DartType expressionType, Name unaryName) {
4231
+ ExpressionInferenceResult _computeUnaryExpression (
4232
+ int fileOffset,
4233
+ Expression expression,
4234
+ DartType expressionType,
4235
+ Name unaryName,
4236
+ Map <DartType , NonPromotionReason > Function () whyNotPromoted) {
4225
4237
ObjectAccessTarget unaryTarget = inferrer.findInterfaceMember (
4226
4238
expressionType, unaryName, fileOffset,
4227
4239
includeExtensionMethods: true );
@@ -4352,6 +4364,8 @@ class InferenceVisitor
4352
4364
}
4353
4365
4354
4366
if (! inferrer.isTopLevel && unaryTarget.isNullable) {
4367
+ List <LocatedMessage > context = inferrer.getWhyNotPromotedContext (
4368
+ whyNotPromoted? .call (), unary, (type) => ! type.isPotentiallyNullable);
4355
4369
// TODO(johnniwinther): Special case 'unary-' in messages. It should
4356
4370
// probably be referred to as "Unary operator '-' ...".
4357
4371
return new ExpressionInferenceResult (
@@ -4361,7 +4375,8 @@ class InferenceVisitor
4361
4375
templateNullableOperatorCallError.withArguments (unaryName.text,
4362
4376
expressionType, inferrer.isNonNullableByDefault),
4363
4377
unary.fileOffset,
4364
- unaryName == unaryMinusName ? 1 : unaryName.text.length));
4378
+ unaryName == unaryMinusName ? 1 : unaryName.text.length,
4379
+ context: context));
4365
4380
}
4366
4381
return new ExpressionInferenceResult (unaryType, unary);
4367
4382
}
@@ -5121,7 +5136,8 @@ class InferenceVisitor
5121
5136
left,
5122
5137
readType,
5123
5138
node.binaryName,
5124
- node.rhs);
5139
+ node.rhs,
5140
+ null );
5125
5141
Expression binary = binaryResult.expression;
5126
5142
DartType binaryType = binaryResult.inferredType;
5127
5143
@@ -5263,7 +5279,8 @@ class InferenceVisitor
5263
5279
left,
5264
5280
readType,
5265
5281
node.binaryName,
5266
- node.rhs);
5282
+ node.rhs,
5283
+ null );
5267
5284
Expression binary = binaryResult.expression;
5268
5285
DartType binaryType = binaryResult.inferredType;
5269
5286
@@ -5417,7 +5434,8 @@ class InferenceVisitor
5417
5434
left,
5418
5435
readType,
5419
5436
node.binaryName,
5420
- node.rhs);
5437
+ node.rhs,
5438
+ null );
5421
5439
Expression binary = binaryResult.expression;
5422
5440
DartType binaryType = binaryResult.inferredType;
5423
5441
@@ -5596,7 +5614,8 @@ class InferenceVisitor
5596
5614
left,
5597
5615
readType,
5598
5616
node.binaryName,
5599
- node.rhs);
5617
+ node.rhs,
5618
+ null );
5600
5619
5601
5620
Expression binary = binaryResult.expression;
5602
5621
DartType binaryType = binaryResult.inferredType;
@@ -6922,13 +6941,16 @@ class InferenceVisitor
6922
6941
BinaryExpression node, DartType typeContext) {
6923
6942
ExpressionInferenceResult leftResult =
6924
6943
inferrer.inferExpression (node.left, const UnknownType (), true );
6944
+ Map <DartType , NonPromotionReason > Function () whyNotPromoted =
6945
+ inferrer.flowAnalysis? .whyNotPromoted (leftResult.expression);
6925
6946
return _computeBinaryExpression (
6926
6947
node.fileOffset,
6927
6948
typeContext,
6928
6949
leftResult.expression,
6929
6950
leftResult.inferredType,
6930
6951
node.binaryName,
6931
- node.right);
6952
+ node.right,
6953
+ whyNotPromoted);
6932
6954
}
6933
6955
6934
6956
ExpressionInferenceResult visitUnary (
@@ -7001,8 +7023,10 @@ class InferenceVisitor
7001
7023
expressionResult =
7002
7024
inferrer.inferExpression (node.expression, const UnknownType (), true );
7003
7025
}
7026
+ Map <DartType , NonPromotionReason > Function () whyNotPromoted =
7027
+ inferrer.flowAnalysis? .whyNotPromoted (expressionResult.expression);
7004
7028
return _computeUnaryExpression (node.fileOffset, expressionResult.expression,
7005
- expressionResult.inferredType, node.unaryName);
7029
+ expressionResult.inferredType, node.unaryName, whyNotPromoted );
7006
7030
}
7007
7031
7008
7032
ExpressionInferenceResult visitParenthesized (
0 commit comments