Skip to content

Commit 67da8cf

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Fix for NPE when the assigned expression is synthetic at the end of the unit.
[email protected] Change-Id: I6c221481fa0b8338847f6fb0d605c45c17a55fe3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150841 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent b19e907 commit 67da8cf

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

pkg/analysis_server/lib/src/services/correction/dart/change_type_annotation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ChangeTypeAnnotation extends CorrectionProducer {
2323

2424
@override
2525
Future<void> compute(DartChangeBuilder builder) async {
26-
var declaration = coveredNode.parent;
26+
var declaration = coveredNode?.parent;
2727
if (declaration is VariableDeclaration &&
2828
declaration.initializer == coveredNode) {
2929
var variableList = declaration.parent;

pkg/analysis_server/test/abstract_context.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,29 @@ class AbstractContextTest with ResourceProviderMixin {
132132
}
133133

134134
/// Create an analysis options file based on the given arguments.
135-
void createAnalysisOptionsFile(
136-
{List<String> experiments, List<String> lints}) {
135+
void createAnalysisOptionsFile({
136+
List<String> experiments,
137+
bool implicitCasts,
138+
List<String> lints,
139+
}) {
137140
var buffer = StringBuffer();
138141

139-
if (experiments != null) {
142+
if (experiments != null || implicitCasts != null) {
140143
buffer.writeln('analyzer:');
144+
}
145+
146+
if (experiments != null) {
141147
buffer.writeln(' enable-experiment:');
142148
for (var experiment in experiments) {
143149
buffer.writeln(' - $experiment');
144150
}
145151
}
146152

153+
if (implicitCasts != null) {
154+
buffer.writeln(' strong-mode:');
155+
buffer.writeln(' implicit-casts: $implicitCasts');
156+
}
157+
147158
if (lints != null) {
148159
buffer.writeln('linter:');
149160
buffer.writeln(' rules:');

pkg/analysis_server/test/src/services/correction/fix/change_type_annotation_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/src/services/correction/fix.dart';
6+
import 'package:analyzer/src/error/codes.dart';
67
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
78
import 'package:test_reflective_loader/test_reflective_loader.dart';
89

@@ -69,4 +70,16 @@ main() {
6970
}
7071
''');
7172
}
73+
74+
Future<void> test_synthetic_implicitCast() async {
75+
createAnalysisOptionsFile(implicitCasts: false);
76+
await resolveTestUnit('''
77+
int foo =
78+
''');
79+
await assertNoFix(
80+
errorFilter: (e) {
81+
return e.errorCode == StaticTypeWarningCode.INVALID_ASSIGNMENT;
82+
},
83+
);
84+
}
7285
}

0 commit comments

Comments
 (0)