Remove a warning (issue 31351)

Change-Id: Id798aa7ece345970e3bfba15b260df6482a57074
Reviewed-on: https://dart-review.googlesource.com/37861
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2018-01-31 20:42:26 +00:00 committed by commit-bot@chromium.org
parent 450765c64e
commit b74ceb0248
6 changed files with 14 additions and 309 deletions

View file

@ -568,7 +568,6 @@ const List<ErrorCode> errorCodeValues = const [
StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED,
StaticWarningCode.IMPORT_OF_NON_LIBRARY,
StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD,
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC,
StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE,
StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE,
StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE,

View file

@ -3809,22 +3809,6 @@ class StaticWarningCode extends ErrorCode {
"Try adjusting the supertypes of this class to remove the "
"inconsistency.");
/**
* 7.1 Instance Methods: It is a static warning if a class <i>C</i> declares
* an instance method named <i>n</i> and an accessible static member named
* <i>n</i> is declared in a superclass of <i>C</i>.
*
* Parameters:
* 0: the name of the member with the name conflict
* 1: the name of the enclosing class that has the static member
*/
static const StaticWarningCode
INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC =
const StaticWarningCode(
'INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC',
"'{0}' collides with a static member in the superclass '{1}'.",
"Try renaming either the method or the inherited member.");
/**
* 7.2 Getters: It is a static warning if a getter <i>m1</i> overrides a
* getter <i>m2</i> and the type of <i>m1</i> is not a subtype of the type of

View file

@ -1725,8 +1725,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
* overriding. The [parameters] is the parameters of the executable element.
* The [errorNameTarget] is the node to report problems on.
*
* See [StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC],
* [CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED],
* See [CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED],
* [CompileTimeErrorCode.INVALID_OVERRIDE_POSITIONAL],
* [CompileTimeErrorCode.INVALID_OVERRIDE_NAMED],
* [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE],
@ -2092,10 +2091,6 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
//
List<ExecutableElement> overriddenExecutables = _inheritanceManager
.lookupOverrides(_enclosingClass, executableElement.name);
if (_checkForInstanceMethodNameCollidesWithSuperclassStatic(
executableElement, errorNameTarget)) {
return;
}
for (ExecutableElement overriddenElement in overriddenExecutables) {
if (_checkForAllInvalidOverrideErrorCodes(executableElement,
overriddenElement, parameters, parameterLocations, errorNameTarget)) {
@ -4351,81 +4346,6 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
}
/**
* Check whether the given [executableElement] collides with the name of a
* static method in one of its superclasses, and reports the appropriate
* warning if it does. The [errorNameTarget] is the node to report problems
* on.
*
* See [StaticTypeWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC].
*/
bool _checkForInstanceMethodNameCollidesWithSuperclassStatic(
ExecutableElement executableElement, SimpleIdentifier errorNameTarget) {
String executableElementName = executableElement.name;
if (executableElement is! PropertyAccessorElement &&
!executableElement.isOperator) {
HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>();
InterfaceType superclassType = _enclosingClass.supertype;
ClassElement superclassElement = superclassType?.element;
bool executableElementPrivate =
Identifier.isPrivateName(executableElementName);
while (superclassElement != null &&
!visitedClasses.contains(superclassElement)) {
visitedClasses.add(superclassElement);
LibraryElement superclassLibrary = superclassElement.library;
// Check fields.
FieldElement fieldElt =
superclassElement.getField(executableElementName);
if (fieldElt != null) {
// Ignore if private in a different library - cannot collide.
if (executableElementPrivate &&
_currentLibrary != superclassLibrary) {
continue;
}
// instance vs. static
if (fieldElt.isStatic) {
_errorReporter.reportErrorForNode(
StaticWarningCode
.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC,
errorNameTarget,
[executableElementName, fieldElt.enclosingElement.displayName]);
return true;
}
}
// Check methods.
List<MethodElement> methodElements = superclassElement.methods;
int length = methodElements.length;
for (int i = 0; i < length; i++) {
MethodElement methodElement = methodElements[i];
// We need the same name.
if (methodElement.name != executableElementName) {
continue;
}
// Ignore if private in a different library - cannot collide.
if (executableElementPrivate &&
_currentLibrary != superclassLibrary) {
continue;
}
// instance vs. static
if (methodElement.isStatic) {
_errorReporter.reportErrorForNode(
StaticWarningCode
.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC,
errorNameTarget,
[
executableElementName,
methodElement.enclosingElement.displayName
]);
return true;
}
}
superclassType = superclassElement.supertype;
superclassElement = superclassType?.element;
}
}
return false;
}
/**
* Verify that an 'int' can be assigned to the parameter corresponding to the
* given [argument]. This is used for prefix and postfix expressions where

View file

@ -832,70 +832,6 @@ class StaticWarningCodeTest_Kernel extends StaticWarningCodeTest_Driver {
return super.test_inconsistentMethodInheritanceGetterAndMethod();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_field() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_field();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_field2() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_field2();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_getter() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_getter();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_getter2() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_getter2();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_interface() async {
return super
.test_instanceMethodNameCollidesWithSuperclassStatic_interface();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_method() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_method();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_method2() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_method2();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_setter() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_setter();
}
@override
@failingTest
@potentialAnalyzerProblem
test_instanceMethodNameCollidesWithSuperclassStatic_setter2() async {
return super.test_instanceMethodNameCollidesWithSuperclassStatic_setter2();
}
@override
@failingTest
@potentialAnalyzerProblem

View file

@ -1559,153 +1559,6 @@ class C implements A, B {
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_field() async {
Source source = addSource(r'''
class A {
static var n;
}
class B extends A {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_field2() async {
Source source = addSource(r'''
class A {
static var n;
}
class B extends A {
}
class C extends B {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_getter() async {
Source source = addSource(r'''
class A {
static get n {return 0;}
}
class B extends A {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_getter2() async {
Source source = addSource(r'''
class A {
static get n {return 0;}
}
class B extends A {
}
class C extends B {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_interface() async {
Source source = addSource(r'''
class Base {
static foo() {}
}
abstract class Ifc {
foo();
}
class C extends Base implements Ifc {
foo() {}
}
''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_method() async {
Source source = addSource(r'''
class A {
static n () {}
}
class B extends A {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_method2() async {
Source source = addSource(r'''
class A {
static n () {}
}
class B extends A {
}
class C extends B {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_setter() async {
Source source = addSource(r'''
class A {
static set n(int x) {}
}
class B extends A {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_instanceMethodNameCollidesWithSuperclassStatic_setter2() async {
Source source = addSource(r'''
class A {
static set n(int x) {}
}
class B extends A {
}
class C extends B {
void n() {}
}''');
await computeAnalysisResult(source);
assertErrors(source, [
StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
]);
verify([source]);
}
test_invalidGetterOverrideReturnType() async {
Source source = addSource(r'''
class A {

View file

@ -3,12 +3,25 @@
# BSD-style license that can be found in the LICENSE file.
[ $compiler == dart2analyzer ]
Language/Classes/Abstract_Instance_Members/same_name_static_method_in_superclass_t01: MissingStaticWarning # test is out of date
Language/Classes/Abstract_Instance_Members/same_name_static_method_in_superclass_t02: MissingStaticWarning # test is out of date
Language/Classes/Abstract_Instance_Members/same_name_static_method_in_superclass_t04: MissingStaticWarning # test is out of date
Language/Classes/Abstract_Instance_Members/same_name_static_method_in_superclass_t05: MissingStaticWarning # test is out of date
Language/Classes/Abstract_Instance_Members/same_name_static_method_in_superclass_t06: MissingStaticWarning # test is out of date
Language/Classes/Classes/method_definition_t06: MissingStaticWarning # Please triage this failure.
Language/Classes/Getters/static_getter_t02: CompileTimeError # Issue 24534
Language/Classes/Getters/static_t01: StaticWarning # Please triage this failure.
Language/Classes/Getters/void_return_type_t01: MissingStaticWarning # Issue co19/30264
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t01: MissingStaticWarning # test is out of date
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t02: MissingStaticWarning # test is out of date
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t04: MissingStaticWarning # test is out of date
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t05: MissingStaticWarning # test is out of date
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t06: MissingStaticWarning # test is out of date
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t07: MissingStaticWarning # test is out of date
Language/Classes/Instance_Methods/same_name_static_member_in_superclass_t09: MissingStaticWarning # test is out of date
Language/Classes/Instance_Variables/definition_t03: StaticWarning # Please triage this failure.
Language/Classes/Static_Methods/same_name_method_and_setter_t01: MissingStaticWarning # Issue 23749
Language/Classes/Superclasses/Inheritance_and_Overriding/inheritance_t02: MissingStaticWarning # test is out of date
Language/Classes/Superclasses/Inheritance_and_Overriding/inheritance_t05: MissingStaticWarning # TBF: Static members should not be accessible via subclasses.
Language/Classes/definition_t23: CompileTimeError # This seems correct, need to adjust test.
Language/Classes/method_definition_t06: MissingStaticWarning # Please triage this failure.