@@ -513,16 +513,25 @@ class ResolverVisitor extends ScopedVisitor {
513
513
}
514
514
515
515
/// Computes the appropriate set of context messages to report along with an
516
- /// error that may have occurred because [receiver] was not type promoted.
516
+ /// error that may have occurred because [expression] was not type promoted.
517
+ ///
518
+ /// If [expression] is `null` , it means the expression that was not type
519
+ /// promoted was an implicit `this` .
520
+ ///
521
+ /// [errorEntity] is the entity whose location will be associated with the
522
+ /// error. This is needed for test instrumentation.
523
+ ///
524
+ /// [whyNotPromoted] should be the non-promotion details returned by the flow
525
+ /// analysis engine.
517
526
List <DiagnosticMessage > computeWhyNotPromotedMessages (
518
- Expression ? receiver ,
527
+ Expression ? expression ,
519
528
SyntacticEntity errorEntity,
520
529
Map <DartType , NonPromotionReason >? whyNotPromoted) {
521
530
List <DiagnosticMessage > messages = [];
522
531
if (whyNotPromoted != null ) {
523
532
for (var entry in whyNotPromoted.entries) {
524
533
var whyNotPromotedVisitor = _WhyNotPromotedVisitor (
525
- source, receiver , errorEntity, flowAnalysis! .dataForTesting);
534
+ source, expression , errorEntity, flowAnalysis! .dataForTesting);
526
535
if (typeSystem.isPotentiallyNullable (entry.key)) continue ;
527
536
var message = entry.value.accept (whyNotPromotedVisitor);
528
537
if (message != null ) {
@@ -3353,7 +3362,9 @@ class _WhyNotPromotedVisitor
3353
3362
PromotableElement , DartType > {
3354
3363
final Source source;
3355
3364
3356
- final Expression ? _receiver;
3365
+ /// The expression that was not promoted, or `null` if the thing that was not
3366
+ /// promoted was an implicit `this` .
3367
+ final Expression ? _expression;
3357
3368
3358
3369
final SyntacticEntity _errorEntity;
3359
3370
@@ -3364,7 +3375,7 @@ class _WhyNotPromotedVisitor
3364
3375
DartType ? propertyType;
3365
3376
3366
3377
_WhyNotPromotedVisitor (
3367
- this .source, this ._receiver , this ._errorEntity, this ._dataForTesting);
3378
+ this .source, this ._expression , this ._errorEntity, this ._dataForTesting);
3368
3379
3369
3380
@override
3370
3381
DiagnosticMessage ? visitDemoteViaExplicitWrite (
@@ -3410,24 +3421,25 @@ class _WhyNotPromotedVisitor
3410
3421
@override
3411
3422
DiagnosticMessage ? visitPropertyNotPromoted (
3412
3423
PropertyNotPromoted <DartType > reason) {
3413
- var receiver = _receiver ;
3424
+ var expression = _expression ;
3414
3425
Element ? receiverElement;
3415
- if (receiver is SimpleIdentifier ) {
3416
- receiverElement = receiver .staticElement;
3417
- } else if (receiver is PropertyAccess ) {
3418
- receiverElement = receiver .propertyName.staticElement;
3419
- } else if (receiver is PrefixedIdentifier ) {
3420
- receiverElement = receiver .identifier.staticElement;
3426
+ if (expression is SimpleIdentifier ) {
3427
+ receiverElement = expression .staticElement;
3428
+ } else if (expression is PropertyAccess ) {
3429
+ receiverElement = expression .propertyName.staticElement;
3430
+ } else if (expression is PrefixedIdentifier ) {
3431
+ receiverElement = expression .identifier.staticElement;
3421
3432
} else {
3422
- assert (false , 'Unrecognized receiver: ${receiver .runtimeType }' );
3433
+ assert (false ,
3434
+ 'Unrecognized property access expression: ${expression .runtimeType }' );
3423
3435
}
3424
3436
if (receiverElement is PropertyAccessorElement ) {
3425
3437
propertyReference = receiverElement;
3426
3438
propertyType = reason.staticType;
3427
3439
return _contextMessageForProperty (receiverElement, reason.propertyName);
3428
3440
} else {
3429
3441
assert (receiverElement == null ,
3430
- 'Unrecognized receiver element: ${receiverElement .runtimeType }' );
3442
+ 'Unrecognized property element: ${receiverElement .runtimeType }' );
3431
3443
return null ;
3432
3444
}
3433
3445
}
0 commit comments