Skip to content

Incorrect reflection call leads to compilation errors #1024

Description

@EgorkaKulikov

Description

Try to generate tests for the following class, set timeout at least to 60s.

importorg.antlr.runtime.tree.TreeVisitor;
importorg.antlr.runtime.tree.TreeVisitorAction;
importorg.antlr.v4.parse.GrammarASTAdaptor;
importorg.antlr.v4.tool.ast.GrammarAST;
publicclassGrammarin {
publicvoidsetGrammarPtr(finalorg.antlr.v4.tool.Grammarg, GrammarASTtree) {
if (tree != null) {
TreeVisitorv = newTreeVisitor(newGrammarASTAdaptor());
v.visit(tree, newTreeVisitorAction() {
publicObjectpre(Objectt) {
((GrammarAST) t).g = g;
returnt;
}
publicObjectpost(Objectt) {
returnt;
}
});
}
}
}

The following code i generated:

@Test@DisplayName("setGrammarPtr: -> tree != null : True")
publicvoidtestSetGrammarPtr_TreeNotEqualsNull_2() throwsClassNotFoundException, NoSuchFieldException, IllegalAccessException {
Grammaringrammarin = newGrammarin();
GrammarRootASTtree = newGrammarRootAST(null);
tree.token = null;
ClassbaseTreeClazz = Class.forName("org.antlr.runtime.tree.BaseTree");
FieldchildrenField = baseTreeClazz.getDeclaredField("children");
childrenField.setAccessible(true);
childrenField.get(tree) = newArrayList();
grammarin.setGrammarPtr(null, tree);
}

Line with getter leads to the compilation error

childrenField.get(tree) = new ArrayList(); - variable expected

Metadata

Metadata

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions