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

Name collision in generated ast.ts #1591

Open
ydaveluy opened this issue Jul 21, 2024 · 2 comments
Open

Name collision in generated ast.ts #1591

ydaveluy opened this issue Jul 21, 2024 · 2 comments
Labels
ast AST structure related issue bug Something isn't working

Comments

@ydaveluy
Copy link
Contributor

ydaveluy commented Jul 21, 2024

When defining in mydsl.langium file an interface named Reference, the generated ast.ts does not compile.

Langium version: 3.1
Package name: langium

Steps To Reproduce

define an interface named 'Reference' in mydsl.langium

interface Reference {
name:string
}

Build the project

The current behavior

The project fails to build due to a conflict with imported types from langium in src/language/generated/ast.ts:
import type { AstNode, Reference, ReferenceInfo, TypeMetaData } from 'langium';

The expected behavior

Definition of interfaces like AstNode, Reference, ReferenceInfo or TypeMetaData in langium file should not collide with imports.

@ydaveluy ydaveluy added the bug Something isn't working label Jul 21, 2024
@msujew msujew added the ast AST structure related issue label Jul 21, 2024
@msujew
Copy link
Member

msujew commented Jul 21, 2024

We have a validation for protecting against name collisions with the JavaScript runtime. See here. We would need a separate list for reserved names of the Langium imports.

@ydaveluy
Copy link
Contributor Author

Another alternative would be to import types with a specific prefix (e.g. _langium_) and to prohibit rule names in the grammar from starting with this prefix ?

e.g:

import type { AstNode as _langium_AstNode, 
Reference as _langium_Reference, 
ReferenceInfo as _langium_ReferenceInfo, 
TypeMetaData as _langium_TypeMetaData } from 'langium';

I don't know if this concept would be valid for other reserved keywords.

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

No branches or pull requests

2 participants