Skip to content

Commit 86efd35

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

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7-
import 'package:analyzer/dart/element/element.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
88
import 'package:analyzer/dart/element/type.dart';
99
import 'package:analyzer/dart/element/type_provider.dart';
1010

@@ -57,8 +57,9 @@ class _Visitor extends SimpleAstVisitor<void> {
5757
var loopType = loopParts.iterable.staticType;
5858
if (loopType is! InterfaceType) return;
5959

60-
var iterableType = loopType.asInstanceOf(typeProvider.iterableElement);
60+
var iterableType = loopType.asInstanceOf2(typeProvider.iterableElement2);
6161
if (iterableType == null) return;
62+
6263
if (iterableType.typeArguments.isNotEmpty &&
6364
iterableType.typeArguments.first == staticType) {
6465
rule.reportLint(loopVariableType);
@@ -100,12 +101,12 @@ class _Visitor extends SimpleAstVisitor<void> {
100101
extension on Expression {
101102
bool get dependsOnDeclaredTypeForInference {
102103
if (this case MethodInvocation(:var methodName, typeArguments: null)) {
103-
var element = methodName.staticElement;
104-
if (element is FunctionElement) {
105-
if (element.returnType is TypeParameterType) {
106-
return true;
107-
}
108-
}
104+
var element = methodName.element;
105+
return switch (element) {
106+
LocalFunctionElement() => element.returnType is TypeParameterType,
107+
TopLevelFunctionElement() => element.returnType is TypeParameterType,
108+
_ => false,
109+
};
109110
}
110111
return false;
111112
}

0 commit comments

Comments
 (0)