langium icon indicating copy to clipboard operation
langium copied to clipboard

Cyclic inheritance of types

Open pluralia opened this issue 2 years ago • 2 comments

Some grammars produce cyclic inherited types. For example, these 2 grammars

A infers TypeA:
    B ({infer TypeC.left=current} name=ID)*;

B infers TypeB:
    '(' A ')' | {infer TypeD} value=NUMBER;
A infers TypeA:
    B C*;

B infers TypeB:
    '(' A ')' | D;

generate these types:

export type TypeA = TypeB | TypeC;
export type TypeB = TypeA | TypeD;

TypeA here inherits TypeB and TypeB inherits TypeA, what brings TS errors. We should forbid cyclic inheritance by a validation error.

The validation error should be shown for declared types, too:

type TypeA = TypeB | TypeC;
type TypeB = TypeA | TypeD;

pluralia avatar May 16 '22 16:05 pluralia

I think I'm experiencing something like this problem myself. Is this issue still open?

jtenner avatar Feb 13 '23 18:02 jtenner

@jtenner I've assigned you :)

msujew avatar Feb 13 '23 19:02 msujew