Skip to content

Commit db7dc80

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate unnecessary_null_checks
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I029a4f40344c179ba205a73b453da639452b220f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390264 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent ba1a9ae commit db7dc80

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ lib/src/rules/avoid_function_literals_in_foreach_calls.dart
2525
lib/src/rules/avoid_implementing_value_types.dart
2626
lib/src/rules/avoid_js_rounded_ints.dart
2727
lib/src/rules/avoid_multiple_declarations_per_line.dart
28-
lib/src/rules/avoid_null_checks_in_equality_operators.dart
2928
lib/src/rules/avoid_print.dart
3029
lib/src/rules/avoid_private_typedef_functions.dart
3130
lib/src/rules/avoid_relative_lib_imports.dart
@@ -233,6 +232,7 @@ test/rules/avoid_implementing_value_types_test.dart
233232
test/rules/avoid_init_to_null_test.dart
234233
test/rules/avoid_js_rounded_ints_test.dart
235234
test/rules/avoid_multiple_declarations_per_line_test.dart
235+
test/rules/avoid_null_checks_in_equality_operators_test.dart
236236
test/rules/avoid_positional_boolean_parameters_test.dart
237237
test/rules/avoid_print_test.dart
238238
test/rules/avoid_private_typedef_functions_test.dart

pkg/linter/lib/src/rules/unnecessary_null_checks.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ DartType? getExpectedType(PostfixExpression node) {
6565
}
6666
// in variable declaration
6767
if (parent is VariableDeclaration) {
68-
return parent.declaredElement?.type;
68+
var element = parent.declaredFragment?.element ?? parent.declaredElement2;
69+
return element?.type;
6970
}
7071
// as right member of binary operator
7172
if (parent is BinaryExpression && parent.rightOperand == realNode) {
72-
var parentElement = parent.staticElement;
73+
var parentElement = parent.element;
7374
if (parentElement == null) {
7475
return null;
7576
}
76-
return parentElement.parameters.first.type;
77+
return parentElement.formalParameters.first.type;
7778
}
7879
// as member of list
7980
if (parent is ListLiteral) {
@@ -107,7 +108,7 @@ DartType? getExpectedType(PostfixExpression node) {
107108
if (parent is ArgumentList && realNode is Expression) {
108109
var grandParent = parent.parent;
109110
if (grandParent is InstanceCreationExpression) {
110-
var constructor = grandParent.constructorName.staticElement;
111+
var constructor = grandParent.constructorName.element;
111112
if (constructor != null) {
112113
if (constructor.returnType.isDartAsyncFuture &&
113114
constructor.name == 'value') {
@@ -126,7 +127,7 @@ DartType? getExpectedType(PostfixExpression node) {
126127
}
127128
}
128129
}
129-
return realNode.staticParameterElement?.type;
130+
return realNode.correspondingParameter?.type;
130131
}
131132
return null;
132133
}

0 commit comments

Comments
 (0)