langium icon indicating copy to clipboard operation
langium copied to clipboard

When determining implemented interfaces in union types langium should honor inheritance hierarchy

Open m-novikov opened this issue 8 months ago • 5 comments

Langium version: 3.0, 3.1 Package name: langium

Steps To Reproduce

  1. Given the following grammar:
grammar HelloWorld

entry Model:
    (entities+=Entity | receptors+=Receptor)*;

interface Base {}
interface Person extends Base {name: string}
interface Receptor {in: Base}

Person returns Person:
    'person' name=ID;

Bot returns Base: {infer Bot}
    'id' id=ID;

Entity: Bot | Person;

Receptor returns Receptor:
    'receptor' in=Entity;

hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;

hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;
  1. Try to generate using "langium:generate" command.

The current behavior

Compilation fails with message:

The assigned type 'Entity' is not compatible with the declared property 'in' of type 'Base'.

The expected behavior

Compilation takes into account that interface Person also extends Base and compilation completes.

m-novikov avatar Jun 13 '24 09:06 m-novikov