Skip to content

Commit 2724b00

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Clarify nomenclature for computeWhyNotPromotedMessages.
It's been a while since I worked with this method and I'd forgotten what the parameters meant. A sure sign that documentation and clarification are needed! :) Bug: #44898 Change-Id: I815c35af243ed6c9611346a058a1c1bb37ace4db Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191480 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent e64daf8 commit 2724b00

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,25 @@ class ResolverVisitor extends ScopedVisitor {
513513
}
514514

515515
/// 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.
517526
List<DiagnosticMessage> computeWhyNotPromotedMessages(
518-
Expression? receiver,
527+
Expression? expression,
519528
SyntacticEntity errorEntity,
520529
Map<DartType, NonPromotionReason>? whyNotPromoted) {
521530
List<DiagnosticMessage> messages = [];
522531
if (whyNotPromoted != null) {
523532
for (var entry in whyNotPromoted.entries) {
524533
var whyNotPromotedVisitor = _WhyNotPromotedVisitor(
525-
source, receiver, errorEntity, flowAnalysis!.dataForTesting);
534+
source, expression, errorEntity, flowAnalysis!.dataForTesting);
526535
if (typeSystem.isPotentiallyNullable(entry.key)) continue;
527536
var message = entry.value.accept(whyNotPromotedVisitor);
528537
if (message != null) {
@@ -3353,7 +3362,9 @@ class _WhyNotPromotedVisitor
33533362
PromotableElement, DartType> {
33543363
final Source source;
33553364

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;
33573368

33583369
final SyntacticEntity _errorEntity;
33593370

@@ -3364,7 +3375,7 @@ class _WhyNotPromotedVisitor
33643375
DartType? propertyType;
33653376

33663377
_WhyNotPromotedVisitor(
3367-
this.source, this._receiver, this._errorEntity, this._dataForTesting);
3378+
this.source, this._expression, this._errorEntity, this._dataForTesting);
33683379

33693380
@override
33703381
DiagnosticMessage? visitDemoteViaExplicitWrite(
@@ -3410,24 +3421,25 @@ class _WhyNotPromotedVisitor
34103421
@override
34113422
DiagnosticMessage? visitPropertyNotPromoted(
34123423
PropertyNotPromoted<DartType> reason) {
3413-
var receiver = _receiver;
3424+
var expression = _expression;
34143425
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;
34213432
} else {
3422-
assert(false, 'Unrecognized receiver: ${receiver.runtimeType}');
3433+
assert(false,
3434+
'Unrecognized property access expression: ${expression.runtimeType}');
34233435
}
34243436
if (receiverElement is PropertyAccessorElement) {
34253437
propertyReference = receiverElement;
34263438
propertyType = reason.staticType;
34273439
return _contextMessageForProperty(receiverElement, reason.propertyName);
34283440
} else {
34293441
assert(receiverElement == null,
3430-
'Unrecognized receiver element: ${receiverElement.runtimeType}');
3442+
'Unrecognized property element: ${receiverElement.runtimeType}');
34313443
return null;
34323444
}
34333445
}

0 commit comments

Comments
 (0)