Skip to content

Commit bc2a8a1

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

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class _Visitor extends SimpleAstVisitor<void> {
4343

4444
void check(AstNode node) {
4545
if (node is! DeclaredVariablePattern) return;
46-
var type = node.declaredElement?.type;
46+
var type = node.declaredElement2?.type;
4747
if (type == null) return;
4848
if (type is DynamicType) return;
4949
var valueType = node.matchedValueType;
@@ -89,17 +89,14 @@ class _Visitor extends SimpleAstVisitor<void> {
8989
}
9090

9191
void _visit(VariableDeclaration variable) {
92-
if (!variable.isFinal && !variable.isConst) {
93-
return;
94-
}
95-
if (variable.isSynthetic) {
96-
return;
97-
}
92+
if (!variable.isFinal && !variable.isConst) return;
93+
if (variable.isSynthetic) return;
94+
9895
var initializerType = variable.initializer?.staticType;
99-
if (initializerType == null) {
100-
return;
101-
}
102-
var declaredElement = variable.declaredElement;
96+
if (initializerType == null) return;
97+
98+
var declaredElement =
99+
variable.declaredElement2 ?? variable.declaredFragment?.element;
103100
if (declaredElement == null || declaredElement.type is DynamicType) {
104101
return;
105102
}

0 commit comments

Comments
 (0)