File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
main/java/com/google/errorprone/bugpatterns
test/java/com/google/errorprone/bugpatterns Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,8 @@ private TypeCompatibilityReport compatibilityOfTypes(
82
82
}
83
83
84
84
// If they're the exact same type, they are definitely compatible.
85
- if (state .getTypes ().isSameType (upperBound (leftType ), upperBound (rightType ))) {
85
+ Types types = state .getTypes ();
86
+ if (types .isSameType (upperBound (leftType ), upperBound (rightType ))) {
86
87
return TypeCompatibilityReport .compatible ();
87
88
}
88
89
@@ -103,7 +104,7 @@ private TypeCompatibilityReport compatibilityOfTypes(
103
104
// class Bar extends Super<String>
104
105
// class Foo extends Super<Integer>
105
106
// Bar and Foo would least-upper-bound to Super, and we compare String and Integer to each-other
106
- Type commonSupertype = state . getTypes (). lub (rightType , leftType );
107
+ Type commonSupertype = types . lub ( types . erasure (rightType ), types . erasure ( leftType ) );
107
108
// primitives, etc. can't have a common superclass.
108
109
if (commonSupertype .getTag ().equals (TypeTag .BOT )
109
110
|| commonSupertype .getTag ().equals (TypeTag .ERROR )) {
Original file line number Diff line number Diff line change @@ -120,4 +120,35 @@ public void methodReference_comparableTypes_noFinding() {
120
120
"}" )
121
121
.doTest ();
122
122
}
123
+
124
+ @ Test
125
+ public void wildcards_whenIncompatible () {
126
+ compilationHelper
127
+ .addSourceLines (
128
+ "Test.java" ,
129
+ "" ,
130
+ "public class Test {" ,
131
+ " public void test(Class<? extends Integer> a, Class<? extends String> b) {" ,
132
+ " // BUG: Diagnostic contains:" ,
133
+ " a.equals(b);" ,
134
+ " }" ,
135
+ "}" )
136
+ .doTest ();
137
+ }
138
+
139
+ @ Test
140
+ public void unconstrainedWildcard_compatibleWithAnything () {
141
+ compilationHelper
142
+ .addSourceLines (
143
+ "Test.java" ,
144
+ "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;" ,
145
+ "" ,
146
+ "public class Test {" ,
147
+ " public void test(java.lang.reflect.Method m, Class<?> c) {" ,
148
+ " TestProtoMessage.class.equals(m.getParameterTypes()[0]);" ,
149
+ " TestProtoMessage.class.equals(c);" ,
150
+ " }" ,
151
+ "}" )
152
+ .doTest ();
153
+ }
123
154
}
You can’t perform that action at this time.
0 commit comments