Skip to content

Commit

Permalink
Don't crash when trying to qualify ambiguous simple names
Browse files Browse the repository at this point in the history
Discovered while validating 2.4.0 release (#1639)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=313496085
  • Loading branch information
cushon committed May 29, 2020
1 parent 456716b commit 40b4169
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ public static String qualifyType(VisitorState state, SuggestedFix.Builder fix, S
// Check if the simple name is already visible.
String simpleName = Iterables.getLast(components);
Symbol simpleNameSymbol = FindIdentifiers.findIdent(simpleName, state, KindSelector.VAL_TYP);
if (simpleNameSymbol != null && simpleNameSymbol.getQualifiedName().contentEquals(typeName)) {
if (simpleNameSymbol != null
&& !simpleNameSymbol.getKind().equals(ElementKind.OTHER)
&& simpleNameSymbol.getQualifiedName().contentEquals(typeName)) {
return simpleName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,29 @@ public void negative() {
"}")
.doTest();
}

@Test
public void qualifiedName_ambiguous() {
compilationHelper
.addSourceLines(
"Test.java",
"interface A {",
" interface N {}",
"}",
"interface B extends A {}",
"class C implements D {}",
"interface E extends D {",
" interface N extends D.N {}",
"}",
"interface D {",
" interface N {}",
"}",
"class Test extends C implements E {",
" // BUG: Diagnostic contains: A.N",
" private B.N f() {",
" return null;",
" }",
"}")
.doTest();
}
}

0 comments on commit 40b4169

Please sign in to comment.