Skip to content

Incorrect reflection call leads to compilation errors #1024

Closed
@EgorkaKulikov

Description

@EgorkaKulikov

Description

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

import org.antlr.runtime.tree.TreeVisitor;
import org.antlr.runtime.tree.TreeVisitorAction;
import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.tool.ast.GrammarAST;

public class Grammarin {
    public void setGrammarPtr(final org.antlr.v4.tool.Grammar g, GrammarAST tree) {
        if (tree != null) {
            TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
            v.visit(tree, new TreeVisitorAction() {
                public Object pre(Object t) {
                    ((GrammarAST) t).g = g;
                    return t;
                }

                public Object post(Object t) {
                    return t;
                }
            });
        }
    }
}

The following code i generated:

    @Test
    @DisplayName("setGrammarPtr: -> tree != null : True")
    public void testSetGrammarPtr_TreeNotEqualsNull_2() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
        Grammarin grammarin = new Grammarin();
        GrammarRootAST tree = new GrammarRootAST(null);
        tree.token = null;
        Class baseTreeClazz = Class.forName("org.antlr.runtime.tree.BaseTree");
        Field childrenField = baseTreeClazz.getDeclaredField("children");
        childrenField.setAccessible(true);
        childrenField.get(tree) = new ArrayList();

        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