mike-lischke/antlr4ng

getRuleContext is incompatible with generated code (2.0.5)

EliotVU opened this issue · 7 comments

As seen in this screenshot:
image

The generated code is incompatible with the declared method "getRuleContext", e.g. Argument of type 'typeof IdentifierContext' is not assignable to parameter of type 'new (...args: unknown[]) => IdentifierContext'.ts(2345)

Odd, that was changed in this commit, to allow any constructor. And this change has been published in 2.0.5.

And looking at the bundle I see that code there. Are you sure you have 2.0.5 in your project?

That was my thought at first too, I have confirmed the code is that of 2.0.5, also you can tell by the screenshot's error popup it lists the new type as seen in your commit. :/

Can you post your IdentifierContext class here? Is there something unusual in its constructor?

Try also changing the typings file to use ...args?: unknown[] instead.

I fixed it by changing the type from unknown to any.

As for IdentifierContext its constructor is the default, this error is occurring for all context derivatives.

export class IdentifierContext extends antlr.ParserRuleContext {
    public constructor(parent: antlr.ParserRuleContext | null, invokingState: number) {
        super(parent, invokingState);
    }
}

Meanwhile I saw this in one of my projects too and tbh. I'm totally perplexed. The behavior is different depending on the project, even though the context signatures are the same. All deps are at their latest version (particularly TypeScript) and I don't understand why one project works and the other does not.

Hi there,
Quick note to let you know we've also had this issue and patched it to any temporarily.

This is fixed in 2.0.10