Move LinterContext.resolveNameInScope to a utility function
This utility function is moved to the linter package, closer to the
two callers (two lint rules). The utility function takes with it,
the `LinterNameInScopeResolutionResult` class and
`_LinterNameInScopeResolutionResultState` enum. The implementation is
great, so it's not changed, and the existing API is good too.
Change-Id: I7809661e67ae38fd149466eea6bb45b1b632d7d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365663
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index 680f3f0..4d8ac5d 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -9,7 +9,6 @@
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/dart/element/scope.dart';
import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
@@ -33,7 +32,6 @@
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart'
show AnalysisErrorInfo, AnalysisErrorInfoImpl, AnalysisOptions;
-import 'package:analyzer/src/generated/resolver.dart' show ScopeResolverVisitor;
import 'package:analyzer/src/lint/analysis.dart';
import 'package:analyzer/src/lint/io.dart';
import 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
@@ -238,22 +236,6 @@
/// Returns `true` if the [feature] is enabled in the library being linted.
bool isEnabled(Feature feature);
-
- /// Resolves the name `id` or `id=` (if [setter] is `true`) at the location
- /// of the [node], according to the "16.35 Lexical Lookup" of the language
- /// specification.
- @Deprecated('Use resolveNameInScope2')
- LinterNameInScopeResolutionResult resolveNameInScope(
- String id, bool setter, AstNode node);
-
- /// Resolves the name `id` or `id=` (if [setter] is `true`) at the location
- /// of the [node], according to the "16.35 Lexical Lookup" of the language
- /// specification.
- LinterNameInScopeResolutionResult resolveNameInScope2(
- String id,
- AstNode node, {
- required bool setter,
- });
}
class LinterContextImpl implements LinterContext {
@@ -318,49 +300,6 @@
var unitElement = currentUnit.unit.declaredElement!;
return unitElement.library.featureSet.isEnabled(feature);
}
-
- @override
- LinterNameInScopeResolutionResult resolveNameInScope(
- String id, bool setter, AstNode node) =>
- resolveNameInScope2(id, node, setter: setter);
-
- @override
- LinterNameInScopeResolutionResult resolveNameInScope2(
- String id,
- AstNode node, {
- required bool setter,
- }) {
- Scope? scope;
- for (AstNode? context = node; context != null; context = context.parent) {
- scope = ScopeResolverVisitor.getNodeNameScope(context);
- if (scope != null) {
- break;
- }
- }
-
- if (scope != null) {
- var lookupResult = scope.lookup(id);
- var idElement = lookupResult.getter;
- var idEqElement = lookupResult.setter;
-
- var requestedElement = setter ? idEqElement : idElement;
- var differentElement = setter ? idElement : idEqElement;
-
- if (requestedElement != null) {
- return LinterNameInScopeResolutionResult._requestedName(
- requestedElement,
- );
- }
-
- if (differentElement != null) {
- return LinterNameInScopeResolutionResult._differentName(
- differentElement,
- );
- }
- }
-
- return const LinterNameInScopeResolutionResult._none();
- }
}
class LinterContextParsedImpl implements LinterContext {
@@ -417,19 +356,6 @@
@override
bool isEnabled(Feature feature) =>
throw UnsupportedError('LinterContext with parsed results');
-
- @override
- LinterNameInScopeResolutionResult resolveNameInScope(
- String id, bool setter, AstNode node) =>
- throw UnsupportedError('LinterContext with parsed results');
-
- @override
- LinterNameInScopeResolutionResult resolveNameInScope2(
- String id,
- AstNode node, {
- required bool setter,
- }) =>
- throw UnsupportedError('LinterContext with parsed results');
}
class LinterContextUnit {
@@ -468,38 +394,6 @@
message == null ? "LinterException" : "LinterException: $message";
}
-/// The result of resolving of a basename `id` in a scope.
-class LinterNameInScopeResolutionResult {
- /// The element with the requested basename, `null` is [isNone].
- final Element? element;
-
- /// The state of the result.
- final _LinterNameInScopeResolutionResultState _state;
-
- const LinterNameInScopeResolutionResult._differentName(this.element)
- : _state = _LinterNameInScopeResolutionResultState.differentName;
-
- const LinterNameInScopeResolutionResult._none()
- : element = null,
- _state = _LinterNameInScopeResolutionResultState.none;
-
- const LinterNameInScopeResolutionResult._requestedName(this.element)
- : _state = _LinterNameInScopeResolutionResultState.requestedName;
-
- bool get isDifferentName =>
- _state == _LinterNameInScopeResolutionResultState.differentName;
-
- bool get isNone => _state == _LinterNameInScopeResolutionResultState.none;
-
- bool get isRequestedName =>
- _state == _LinterNameInScopeResolutionResultState.requestedName;
-
- @override
- String toString() {
- return '(state: $_state, element: $element)';
- }
-}
-
class LinterOptions extends DriverOptions {
final Iterable<LintRule> enabledRules;
final String? analysisOptions;
@@ -760,19 +654,6 @@
_LintCode._(super.name, super.message);
}
-/// The state of a [LinterNameInScopeResolutionResult].
-enum _LinterNameInScopeResolutionResultState {
- /// Indicates that no element was found.
- none,
-
- /// Indicates that an element with the requested name was found.
- requestedName,
-
- /// Indicates that an element with the same basename, but different name
- /// was found.
- differentName
-}
-
extension on AstNode {
/// Whether [ConstantVerifier] reports an error when computing the value of
/// `this` as a constant.
diff --git a/pkg/analyzer/test/src/lint/linter/test_all.dart b/pkg/analyzer/test/src/lint/linter/test_all.dart
index 7fa0dca..101588b 100644
--- a/pkg/analyzer/test/src/lint/linter/test_all.dart
+++ b/pkg/analyzer/test/src/lint/linter/test_all.dart
@@ -5,11 +5,9 @@
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'linter_context_impl_test.dart' as linter_context_impl;
-import 'resolve_name_in_scope_test.dart' as resolve_name_in_scope;
main() {
defineReflectiveSuite(() {
linter_context_impl.main();
- resolve_name_in_scope.main();
}, name: 'linter');
}
diff --git a/pkg/linter/lib/src/rules/avoid_types_as_parameter_names.dart b/pkg/linter/lib/src/rules/avoid_types_as_parameter_names.dart
index 6da7056..8e75835 100644
--- a/pkg/linter/lib/src/rules/avoid_types_as_parameter_names.dart
+++ b/pkg/linter/lib/src/rules/avoid_types_as_parameter_names.dart
@@ -8,6 +8,7 @@
import 'package:analyzer/dart/element/element.dart';
import '../analyzer.dart';
+import '../util/scope.dart';
const _desc = r'Avoid types as parameter names.';
@@ -82,7 +83,8 @@
}
bool _isTypeName(AstNode scope, Token name) {
- var result = context.resolveNameInScope2(name.lexeme, scope, setter: false);
+ var result =
+ resolveNameInScope(name.lexeme, scope, shouldResolveSetter: false);
if (result.isRequestedName) {
var element = result.element;
return element is ClassElement ||
diff --git a/pkg/linter/lib/src/rules/unnecessary_this.dart b/pkg/linter/lib/src/rules/unnecessary_this.dart
index 3a601c9..718ffb5 100644
--- a/pkg/linter/lib/src/rules/unnecessary_this.dart
+++ b/pkg/linter/lib/src/rules/unnecessary_this.dart
@@ -8,6 +8,7 @@
import '../analyzer.dart';
import '../ast.dart';
+import '../util/scope.dart';
const _desc = r"Don't access members with `this` unless avoiding shadowing.";
@@ -111,7 +112,7 @@
var id = element.displayName;
var isSetter = element is PropertyAccessorElement && element.isSetter;
- var result = context.resolveNameInScope2(id, node, setter: isSetter);
+ var result = resolveNameInScope(id, node, shouldResolveSetter: isSetter);
// No result, definitely no shadowing.
// The requested element is inherited, or from an extension.
diff --git a/pkg/linter/lib/src/util/scope.dart b/pkg/linter/lib/src/util/scope.dart
new file mode 100644
index 0000000..8f87f3e
--- /dev/null
+++ b/pkg/linter/lib/src/util/scope.dart
@@ -0,0 +1,83 @@
+// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/scope.dart';
+// ignore: implementation_imports
+import 'package:analyzer/src/dart/ast/ast.dart';
+// ignore: implementation_imports
+import 'package:analyzer/src/generated/resolver.dart' show ScopeResolverVisitor;
+
+LinterNameInScopeResolutionResult resolveNameInScope(
+ String id,
+ AstNode node, {
+ required bool shouldResolveSetter,
+}) {
+ Scope? scope;
+ for (AstNode? context = node; context != null; context = context.parent) {
+ scope = ScopeResolverVisitor.getNodeNameScope(context);
+ if (scope != null) {
+ break;
+ }
+ }
+
+ if (scope != null) {
+ var ScopeLookupResult(:setter, :getter) = scope.lookup(id);
+ var requestedElement = shouldResolveSetter ? setter : getter;
+ var differentElement = shouldResolveSetter ? getter : setter;
+
+ if (requestedElement != null) {
+ return LinterNameInScopeResolutionResult._requestedName(requestedElement);
+ }
+
+ if (differentElement != null) {
+ return LinterNameInScopeResolutionResult._differentName(differentElement);
+ }
+ }
+
+ return const LinterNameInScopeResolutionResult._none();
+}
+
+/// The result of resolving of a basename `id` in a scope.
+class LinterNameInScopeResolutionResult {
+ /// The element with the requested basename, `null` is [isNone].
+ final Element? element;
+
+ /// The state of the result.
+ final _LinterNameInScopeResolutionResultState _state;
+
+ const LinterNameInScopeResolutionResult._differentName(this.element)
+ : _state = _LinterNameInScopeResolutionResultState.differentName;
+
+ const LinterNameInScopeResolutionResult._none()
+ : element = null,
+ _state = _LinterNameInScopeResolutionResultState.none;
+
+ const LinterNameInScopeResolutionResult._requestedName(this.element)
+ : _state = _LinterNameInScopeResolutionResultState.requestedName;
+
+ bool get isDifferentName =>
+ _state == _LinterNameInScopeResolutionResultState.differentName;
+
+ bool get isNone => _state == _LinterNameInScopeResolutionResultState.none;
+
+ bool get isRequestedName =>
+ _state == _LinterNameInScopeResolutionResultState.requestedName;
+
+ @override
+ String toString() => '(state: $_state, element: $element)';
+}
+
+/// The state of a [LinterNameInScopeResolutionResult].
+enum _LinterNameInScopeResolutionResultState {
+ /// Indicates that no element was found.
+ none,
+
+ /// Indicates that an element with the requested name was found.
+ requestedName,
+
+ /// Indicates that an element with the same basename, but different name
+ /// was found.
+ differentName
+}
diff --git a/pkg/linter/test/rule_test_support.dart b/pkg/linter/test/rule_test_support.dart
index 6923770..c4d93e3 100644
--- a/pkg/linter/test/rule_test_support.dart
+++ b/pkg/linter/test/rule_test_support.dart
@@ -13,6 +13,8 @@
import 'package:analyzer/src/lint/pub.dart';
import 'package:analyzer/src/lint/registry.dart';
import 'package:analyzer/src/lint/util.dart';
+import 'package:analyzer/src/test_utilities/find_element.dart';
+import 'package:analyzer/src/test_utilities/find_node.dart';
import 'package:analyzer/src/test_utilities/mock_packages.dart';
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
@@ -700,6 +702,10 @@
AnalysisContextCollectionImpl? _analysisContextCollection;
+ late FindElement findElement;
+
+ late FindNode findNode;
+
late ResolvedUnitResult result;
List<String> get collectionIncludedPaths;
@@ -736,7 +742,11 @@
Future<ResolvedUnitResult> resolveFile(String path) async {
var analysisContext = _contextFor(path);
var session = analysisContext.currentSession;
- return await session.getResolvedUnit(path) as ResolvedUnitResult;
+ var result = await session.getResolvedUnit(path) as ResolvedUnitResult;
+
+ findElement = FindElement(result.unit);
+ findNode = FindNode(result.content, result.unit);
+ return result;
}
Future<void> resolveTestFile() => _resolveFile(testFilePath);
diff --git a/pkg/linter/test/rules/use_build_context_synchronously_test.dart b/pkg/linter/test/rules/use_build_context_synchronously_test.dart
index edb8c7e..7bc222d 100644
--- a/pkg/linter/test/rules/use_build_context_synchronously_test.dart
+++ b/pkg/linter/test/rules/use_build_context_synchronously_test.dart
@@ -26,6 +26,7 @@
Element get contextElement =>
findNode.simple('context /* ref */').staticElement!;
+ @override
FindNode get findNode => FindNode(result.content, result.unit);
Future<void> resolveCode(String code) async {
diff --git a/pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart b/pkg/linter/test/scope_util_test.dart
similarity index 84%
rename from pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart
rename to pkg/linter/test/scope_util_test.dart
index 0bac9d5..bafdd3b 100644
--- a/pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart
+++ b/pkg/linter/test/scope_util_test.dart
@@ -1,15 +1,17 @@
-// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// The test method names do not conform to this rule.
+// ignore_for_file: non_constant_identifier_names
+
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/src/error/codes.dart';
+import 'package:linter/src/util/scope.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../../../generated/test_support.dart';
-import 'linter_context_impl_test.dart';
+import 'rule_test_support.dart';
main() {
defineReflectiveSuite(() {
@@ -18,18 +20,9 @@
}
@reflectiveTest
-class ResolveNameInScopeTest extends AbstractLinterContextTest {
- @override
- Future<void> resolve(
- String content, [
- List<ExpectedError> expectedErrors = const [],
- ]) async {
- await super.resolve(content);
- assertErrorsInResolvedUnit(result, expectedErrors);
- }
-
+class ResolveNameInScopeTest extends PubPackageResolutionTest {
test_class_getter_different_fromExtends_thisClassSetter() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
int get foo => 0;
}
@@ -49,7 +42,7 @@
newFile('$testPackageLibPath/a.dart', r'''
set foo(int _) {}
''');
- await resolve('''
+ await assertDiagnostics('''
import 'a.dart';
class A {
@@ -69,7 +62,7 @@
}
test_class_getter_fromExtends_blockBody() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
int get foo => 0;
}
@@ -86,7 +79,7 @@
}
test_class_getter_fromExtends_expressionBody() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
int get foo => 0;
}
@@ -101,7 +94,7 @@
}
test_class_getter_none_fromExtends() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
int get foo => 0;
}
@@ -119,7 +112,7 @@
newFile('$testPackageLibPath/a.dart', r'''
int get foo => 0;
''');
- await resolve('''
+ await assertDiagnostics('''
import 'a.dart';
class A {
@@ -139,7 +132,7 @@
}
test_class_getter_requested_thisClass() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
int get foo => 0;
@@ -152,7 +145,7 @@
}
test_class_method_different_fromExtends_topSetter() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
}
@@ -169,7 +162,7 @@
}
test_class_method_none_fromExtends() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
}
@@ -184,7 +177,7 @@
}
test_class_method_none_fromExtension() async {
- await resolve('''
+ await assertNoDiagnostics('''
extension E on A {
void foo() {}
}
@@ -199,7 +192,7 @@
}
test_class_method_requested_formalParameter_constructor() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -212,7 +205,7 @@
}
test_class_method_requested_formalParameter_method() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -225,7 +218,7 @@
}
test_class_method_requested_fromExtends_topLevelFunction() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
}
@@ -242,7 +235,7 @@
}
test_class_method_requested_fromExtends_topLevelVariable() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
}
@@ -259,7 +252,7 @@
}
test_class_method_requested_fromExtension_topLevelVariable() async {
- await resolve('''
+ await assertNoDiagnostics('''
extension E on A {
void foo() {}
}
@@ -279,7 +272,7 @@
newFile('$testPackageLibPath/a.dart', r'''
void foo() {}
''');
- await resolve('''
+ await assertDiagnostics('''
import 'a.dart';
class A {
@@ -299,7 +292,7 @@
}
test_class_method_requested_localVariable_catchClause() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -316,7 +309,7 @@
}
test_class_method_requested_localVariable_enclosingBlock() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -327,14 +320,12 @@
}
}
}
-''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 50, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_localVariable_forEachElement() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
int foo() => 0;
@@ -342,14 +333,12 @@
return [ for (var foo in []) this.foo() ];
}
}
-''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 71, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_localVariable_forEachStatement() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -359,14 +348,12 @@
}
}
}
-''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 55, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_localVariable_forLoopStatement() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -376,14 +363,12 @@
}
}
}
-''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 55, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_localVariable_switchStatement() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -396,14 +381,12 @@
}
}
}
-''', [
- error(WarningCode.UNUSED_LOCAL_VARIABLE, 94, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_localVariable_thisBlock_after() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -412,14 +395,12 @@
var foo = 0;
}
}
-''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 66, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_localVariable_thisBlock_before() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -428,14 +409,12 @@
this.foo();
}
}
-''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 50, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_patternVariable_ifCase() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -445,14 +424,12 @@
}
}
}
-''', [
- error(WarningCode.UNUSED_LOCAL_VARIABLE, 73, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_patternVariable_switchExpression() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -463,14 +440,12 @@
});
}
}
-''', [
- error(WarningCode.UNUSED_LOCAL_VARIABLE, 82, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_patternVariable_switchStatement() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -481,14 +456,12 @@
}
}
}
-''', [
- error(WarningCode.UNUSED_LOCAL_VARIABLE, 86, 3),
- ]);
+''');
_checkMethodRequestedLocalVariable();
}
test_class_method_requested_thisClass() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -501,7 +474,7 @@
}
test_class_method_requested_typeParameter_method() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo() {}
@@ -514,7 +487,7 @@
}
test_class_method_typeParameter() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
void foo<T>(int T) {}
}
@@ -524,7 +497,7 @@
}
test_class_setter_different_formalParameter_constructor() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
@@ -537,7 +510,7 @@
}
test_class_setter_different_fromExtends_topLevelFunction() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
}
@@ -554,7 +527,7 @@
}
test_class_setter_different_fromExtends_topLevelGetter() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
}
@@ -571,7 +544,7 @@
}
test_class_setter_none_fromExtends() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
}
@@ -586,7 +559,7 @@
}
test_class_setter_requested_fromExtends_topLevelVariable() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
}
@@ -606,7 +579,7 @@
newFile('$testPackageLibPath/a.dart', r'''
set foo(int _) {}
''');
- await resolve('''
+ await assertDiagnostics('''
import 'a.dart';
class A {
@@ -626,7 +599,7 @@
}
test_class_setter_requested_thisClass() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
@@ -639,7 +612,7 @@
}
test_class_setter_requested_thisClass_topLevelFunction() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A {
set foo(int _) {}
@@ -654,7 +627,7 @@
}
test_class_typeParameter_inConstructor() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A<T> {
A(int T) {}
}
@@ -664,7 +637,7 @@
}
test_class_typeParameter_inField() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A<T> {
T? a;
}
@@ -674,7 +647,7 @@
}
test_class_typeParameter_inMethod() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A<T> {
void foo(int T) {}
}
@@ -684,7 +657,7 @@
}
test_class_typeParameter_inSetter() async {
- await resolve('''
+ await assertNoDiagnostics('''
class A<T> {
set foo(int T) {}
}
@@ -694,7 +667,7 @@
}
test_extension_method_none_fromExtended() async {
- await resolve('''
+ await assertDiagnostics('''
class A {
void foo() {}
}
@@ -711,7 +684,7 @@
}
test_extension_method_requested_formalParameter_method() async {
- await resolve('''
+ await assertDiagnostics('''
class A {}
extension on A {
@@ -728,7 +701,7 @@
}
test_extension_method_requested_fromExtended_topLevelVariable() async {
- await resolve('''
+ await assertDiagnostics('''
class A {
void foo() {}
}
@@ -747,7 +720,7 @@
}
test_extension_method_requested_fromThisExtension() async {
- await resolve('''
+ await assertDiagnostics('''
class A {}
extension on A {
@@ -764,7 +737,7 @@
}
test_extension_typeParameter_inMethod() async {
- await resolve('''
+ await assertNoDiagnostics('''
extension E<T> on int {
void foo(int T) {}
}
@@ -774,7 +747,7 @@
}
test_function_typeParameter() async {
- await resolve('''
+ await assertNoDiagnostics('''
void foo<T>(int T) {}
''');
var node = findNode.simpleFormalParameter('T)');
@@ -782,7 +755,7 @@
}
test_genericFunctionType_typeParameter() async {
- await resolve('''
+ await assertNoDiagnostics('''
void foo(void Function<T>(String T) b) {}
''');
var node = findNode.simpleFormalParameter('T)');
@@ -791,7 +764,7 @@
}
test_genericTypeAlias_typeParameter() async {
- await resolve('''
+ await assertNoDiagnostics('''
typedef A<T> = List<T>;
''');
var node = findNode.namedType('T>;');
@@ -799,7 +772,7 @@
}
test_mixin_method_requested_formalParameter_method() async {
- await resolve('''
+ await assertNoDiagnostics('''
mixin M {
void foo() {}
@@ -812,7 +785,7 @@
}
test_mixin_method_requested_thisClass() async {
- await resolve('''
+ await assertNoDiagnostics('''
mixin M {
void foo() {}
@@ -825,7 +798,7 @@
}
test_mixin_typeParameter_inField() async {
- await resolve('''
+ await assertNoDiagnostics('''
mixin A<T> {
T? a;
}
@@ -835,7 +808,7 @@
}
test_mixin_typeParameter_inMethod() async {
- await resolve('''
+ await assertNoDiagnostics('''
mixin A<T> {
void foo(int T) {}
}
@@ -894,21 +867,21 @@
}
void _resultDifferent(AstNode node, String id, bool setter, Element element) {
- var result = context.resolveNameInScope(id, setter, node);
+ var result = resolveNameInScope(id, node, shouldResolveSetter: setter);
if (!result.isDifferentName || result.element != element) {
fail('Expected different $element, actual: $result');
}
}
void _resultNone(AstNode node, String id, bool setter) {
- var result = context.resolveNameInScope(id, setter, node);
+ var result = resolveNameInScope(id, node, shouldResolveSetter: setter);
if (!result.isNone) {
fail('Expected none, actual: $result');
}
}
void _resultRequested(AstNode node, String id, bool setter, Element element) {
- var result = context.resolveNameInScope(id, setter, node);
+ var result = resolveNameInScope(id, node, shouldResolveSetter: setter);
if (!result.isRequestedName || result.element != element) {
fail('Expected requested $element, actual: $result');
}