Skip to content

Commit e0fd546

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Improve "why not promoted" context message for the case of writes.
The new message phrasing should flow better, especially in the analyzer CLI. For the motivation for this change, please see #44904 (comment) Bug: #44898 Change-Id: I595492c64b42aff25cae5a8936c32aa8a218edd8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184601 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent e05ad3a commit e0fd546

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9665,15 +9665,13 @@ const MessageCode messageVarReturnType = const MessageCode("VarReturnType",
96659665
r"""Try removing the keyword 'var', or replacing it with the name of the return type.""");
96669666

96679667
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
9668-
const Template<
9669-
Message Function(
9670-
String
9671-
name)> templateVariableCouldBeNullDueToWrite = const Template<
9672-
Message Function(String name)>(
9673-
messageTemplate:
9674-
r"""Variable '#name' could be null due to a write occurring here.""",
9675-
tipTemplate: r"""Try null checking the variable after the write.""",
9676-
withArguments: _withArgumentsVariableCouldBeNullDueToWrite);
9668+
const Template<Message Function(String name)>
9669+
templateVariableCouldBeNullDueToWrite =
9670+
const Template<Message Function(String name)>(
9671+
messageTemplate:
9672+
r"""Variable '#name' could be null due to an intervening write.""",
9673+
tipTemplate: r"""Try null checking the variable after the write.""",
9674+
withArguments: _withArgumentsVariableCouldBeNullDueToWrite);
96779675

96789676
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
96799677
const Code<Message Function(String name)> codeVariableCouldBeNullDueToWrite =
@@ -9687,7 +9685,7 @@ Message _withArgumentsVariableCouldBeNullDueToWrite(String name) {
96879685
name = demangleMixinApplicationName(name);
96889686
return new Message(codeVariableCouldBeNullDueToWrite,
96899687
message:
9690-
"""Variable '${name}' could be null due to a write occurring here.""",
9688+
"""Variable '${name}' could be null due to an intervening write.""",
96919689
tip: """Try null checking the variable after the write.""",
96929690
arguments: {'name': name});
96939691
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ class _WhyNotPromotedVisitor
392392
String variableName, Expression writeExpression) {
393393
return DiagnosticMessageImpl(
394394
filePath: source.fullName,
395-
message:
396-
"Variable '$variableName' could be null due to a write occurring here.",
395+
message: "Variable '$variableName' could be null due to an intervening "
396+
"write.",
397397
offset: writeExpression.offset,
398398
length: writeExpression.length);
399399
}

pkg/front_end/messages.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4589,7 +4589,7 @@ MultipleVarianceModifiers:
45894589
analyzerCode: ParserErrorCode.MULTIPLE_VARIANCE_MODIFIERS
45904590

45914591
VariableCouldBeNullDueToWrite:
4592-
template: "Variable '#name' could be null due to a write occurring here."
4592+
template: "Variable '#name' could be null due to an intervening write."
45934593
tip: "Try null checking the variable after the write."
45944594

45954595
FieldNotPromoted:

pkg/front_end/test/spell_checking_list_messages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ futureor
3636
h
3737
https
3838
interop
39+
intervening
3940
js_util
4041
libraries.json
4142
list.filled

0 commit comments

Comments
 (0)