Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Langium grammar can declare AST elements with conflicting names #529

Closed
RGHenderson opened this issue Jun 8, 2022 · 1 comment · Fixed by #749
Closed

Langium grammar can declare AST elements with conflicting names #529

RGHenderson opened this issue Jun 8, 2022 · 1 comment · Fixed by #749
Labels
ast AST structure related issue bug Something isn't working
Milestone

Comments

@RGHenderson
Copy link

Langium version: 0.3.0
Package name: langium

Steps To Reproduce

  1. Create a minimal grammar containing an entry rule, and reference to a rule of name 'Error'
  2. Run langium generator3.
  3. Run build
  4. See error something like:
src/language-server/generated/ast.ts:59:27 - error TS2351: This expression is not constructable.
  Type 'String' has no construct signatures.

59                 throw new Error(`${referenceId} is not a valid reference id.`);

Which makes sense given the content of the generated ast.ts:

export interface Error extends AstNode 
...
export const Error = 'Error';

Minimal grammar which causes error:

grammar ErrorExample

entry ErrorExample:
    errors+=Error;

Error:
    'error' name=ID;

terminal ID: /[_a-zA-Z][\w_]*/;

The current behavior

Langium allows the definition of conflicting AST element names, causing the above build error.

The expected behavior

Either the generated AST will be more smart, OR langium grammars are validated against reserved rule names.

@RGHenderson RGHenderson added the bug Something isn't working label Jun 8, 2022
@msujew
Copy link
Member

msujew commented Jun 8, 2022

Thanks for the report @RGHenderson! We should probably add reserved names for built-in JavaScript types. The only other option would be to rename them automatically, which would be quite unintuitive for users.

@msujew msujew added the ast AST structure related issue label Jun 8, 2022
@spoenemann spoenemann added this to the v1.0.0 milestone Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast AST structure related issue bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants