Skip to content

Commit

Permalink
Fix yet another NonCanonicalType crash
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 498021422
  • Loading branch information
cushon authored and Error Prone Team committed Dec 27, 2022
1 parent 5768290 commit e360257
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.Visibility;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.Tree;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.util.Position;
Expand Down Expand Up @@ -115,7 +116,7 @@ private static String createDescription(String canonicalName, String nonCanonica
* Find the non-canonical name which is being used to refer to this type. We can't just use {@code
* getSymbol}, given that points to the same symbol as the canonical name.
*/
private static String getNonCanonicalName(ExpressionTree tree) {
private static String getNonCanonicalName(Tree tree) {
switch (tree.getKind()) {
case IDENTIFIER:
return getSymbol(tree).getQualifiedName().toString();
Expand All @@ -128,8 +129,10 @@ private static String getNonCanonicalName(ExpressionTree tree) {
return getNonCanonicalName(memberSelectTree.getExpression())
+ "."
+ memberSelectTree.getIdentifier();
case PARAMETERIZED_TYPE:
return getNonCanonicalName(((ParameterizedTypeTree) tree).getType());
default:
throw new AssertionError();
throw new AssertionError(tree.getKind());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,27 @@ public void method_noFinding() {
"}")
.doTest();
}

// TODO(cushon): the fix for this should be Super<?>.Inner, not Super.Inner
@Test
public void innerArray() {
compilationHelper
.addSourceLines(
"Super.java", //
"class Super<T> {",
" class Inner {}",
"}")
.addSourceLines(
"Super.java", //
"class Sub<T> extends Super<T> {",
"}")
.addSourceLines(
"Test.java", //
"class Test {",
" // BUG: Diagnostic contains: `Super.Inner` was referred to by the non-canonical name"
+ " `Sub.Inner`",
" Sub<?>.Inner[] x;",
"}")
.doTest();
}
}

0 comments on commit e360257

Please sign in to comment.