Skip to content

Commit

Permalink
Merge pull request #2151 from jjbr/endless-recursion-parent-of-simila…
Browse files Browse the repository at this point in the history
…r-name

Fix for endless recursion bug #2150
  • Loading branch information
matozoid committed Apr 30, 2019
2 parents d3b2dcf + da7de74 commit 2e7bdfe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,6 @@ private ResolvedReferenceType toReferenceType(ClassOrInterfaceType classOrInterf
if (ref == null || !ref.isSolved()) {
ref = solveType(typeName);
}
if (!ref.isSolved() && classOrInterfaceType.getScope().isPresent()) {
ref = solveType(classOrInterfaceType.getName().getId());
}
if (!ref.isSolved()) {
throw new UnsolvedSymbolException(classOrInterfaceType.getName().getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.javaparser.symbolsolver.resolution;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.VariableDeclarationExpr;
import com.github.javaparser.ast.stmt.ExpressionStmt;
import com.github.javaparser.resolution.UnsolvedSymbolException;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.javaparser.Navigator;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;

public class NotQuiteCyclicParentTest extends AbstractResolutionTest {

@Test
void testSimilarNameInterface() {
CompilationUnit cu = parseSample("NotQuiteCyclicParent");
ClassOrInterfaceDeclaration clazz = Navigator.demandInterface(cu, "NotQuiteCyclicParent");
MethodDeclaration method = Navigator.demandMethod(clazz, "main");
VariableDeclarationExpr varDec =
(VariableDeclarationExpr) ((ExpressionStmt) method.getBody().get().getStatement(0)).getExpression();

try {
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(varDec);
} catch (UnsolvedSymbolException e) {
return;
}

fail("We shouldn't be able to resolve the type (it is not defined).");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package foo;

public interface NotQuiteCyclicParent extends bar.NotQuiteCyclicParent {
default void main() {
MyType x = new MyType();
}
}

0 comments on commit 2e7bdfe

Please sign in to comment.