Skip to content

Commit

Permalink
Fixes compile errors due to missing forward declarations for types us…
Browse files Browse the repository at this point in the history
…ed in type narrowing method declarations within private inner classes.

	Change on 2016/11/10 by kstanger <kstanger@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138817999
  • Loading branch information
kstanger authored and tomball committed Nov 17, 2016
1 parent 174299e commit 2d825a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Expand Up @@ -107,10 +107,12 @@ private void printImports() {
String name = generatedType.getTypeName();
seenTypes.add(name);
for (Import imp : generatedType.getImplementationForwardDeclarations()) {
// Only need to forward declare private local types. All else is handled
// by imports.
GeneratedType localType = getLocalType(imp.getTypeName());
if (!seenTypes.contains(imp.getTypeName()) && localType != null && localType.isPrivate()) {
String typeName = imp.getTypeName();
GeneratedType localType = getLocalType(typeName);
// For local types, only forward declare private types that haven't been seen yet.
// For non-local types, only forward declare types that haven't been imported.
if (localType != null ? (localType.isPrivate() && !seenTypes.contains(typeName))
: !includeFiles.contains(imp.getImportFileName())) {
forwardDecls.add(imp);
}
}
Expand Down
Expand Up @@ -829,4 +829,13 @@ public void testAnnotationsAsAnnotationValues() throws IOException {
"A", "A.m");
assertTranslation(translation, "create_A_Outer(create_A_Inner(@\"Bar\"))");
}

public void testForwradDeclarationForPrivateAbstractDeclaration() throws IOException {
// We need a forward declaration of JavaLangInteger for the type narrowing declaration of get()
// in the private class B.
String translation = translateSourceFile(
"class Test { static class A <T> { T get() { return null; } }"
+ "private static class B extends A<Integer> { } }", "Test", "Test.m");
assertTranslation(translation, "@class JavaLangInteger;");
}
}

0 comments on commit 2d825a2

Please sign in to comment.