langium icon indicating copy to clipboard operation
langium copied to clipboard

The strict mode for types inference

Open pluralia opened this issue 3 years ago • 2 comments

In Langium 0.2.0 types are inferred from rules names implicitly. For example, the following 2 examples will infer a type MyRule with the attribute name.

MyRule:
    name=ID;
MyRule returns MyRule:
    name=ID;

When we add types, type inference like described above will still be allowed by default.

This feature issue proposes to add the strict mode, when implicit type inference is forbidden. So, the way to specify a type of MyRule in the strict mode is:

type MyRule = {
    name: string
}

MyRule returns MyRule:
    name=ID;

pluralia avatar Jan 20 '22 19:01 pluralia

We can generate "a type system template" automatically in the strict mode. So, we just infer types like in the "default" mode and put them in separate .langium file. As the result:

  1. The strict mode works out of box
  2. A user develops the type system by adding and modifying types instead of creating everything from zero

@danieldietrich proposed to add that functionality to the CLI.

pluralia avatar Jan 20 '22 19:01 pluralia

This will be considerably easier to implement with #438 and #440.

spoenemann avatar Mar 11 '22 07:03 spoenemann