Skip to content

Commit

Permalink
EqualsIncompatibleType: ignore the Enum supertype when considering if…
Browse files Browse the repository at this point in the history
… two

arguments share a non-Object supertype for warning about incompatible argument
types.

RELNOTES: EqualsIncompatibleType will report when enums of incompatible types
are passed to .equals()

MOE_MIGRATED_REVID=142612571
  • Loading branch information
nick-someone committed Dec 22, 2016
1 parent a164121 commit fe41858
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -123,8 +123,10 @@ public boolean apply(MethodSymbol methodSymbol) {
for (MethodSymbol method : overridesOfEquals) {
ClassSymbol methodClass = method.enclClass();
if (argumentClass.isSubClass(methodClass, types)
&& !methodClass.equals(state.getSymtab().objectType.tsym)) {
// The type of the argument shares a superclass (other then java.lang.Object) or interface
&& !methodClass.equals(state.getSymtab().objectType.tsym)
&& !methodClass.equals(state.getSymtab().enumSym)) {
// The type of the argument shares a superclass
// (other then java.lang.Object or java.lang.Enum) or interface
// with the receiver that implements an override of java.lang.Object.equals().
return Description.NO_MATCH;
}
Expand Down
Expand Up @@ -88,4 +88,20 @@ void checkEqualsDD1D2(D d, D1 d1, D2 d2) {
// BUG: Diagnostic contains: incompatible types
d2.equals(d1);
}

enum MyEnum {}

enum MyOtherEnum {}

void enumEquals(MyEnum m, MyOtherEnum mm) {
// BUG: Diagnostic contains: incompatible types
m.equals(mm);
// BUG: Diagnostic contains: incompatible types
mm.equals(m);

// BUG: Diagnostic contains: incompatible types
com.google.common.base.Objects.equal(m, mm);
// BUG: Diagnostic contains: incompatible types
com.google.common.base.Objects.equal(mm, m);
}
}

0 comments on commit fe41858

Please sign in to comment.