eclipse-xtext / eclipse-xtext/xtext
Cannot use enum from base model for property of external model element
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
Consider the following three grammars that generate ecore models:
- MyDsl - the base grammar, containing the
enumdefinition - MyDsl2 - a grammar inheriting from the base, containing a
ParentModelwith a property using theenumfrom the base grammar - MyDsl3 - a grammar inheriting from the base, containing a
ChildModelthat is a subclass ofParentModel
An error Cannot find compatible feature property in sealed EClass ParentModel from imported package http://www.xtext.org/example/mydsl2/MyDsl2: The existing attribute 'property' has an incompatible type 'Property'. The expected type is 'Property'. prevents using the property from ParentModel in the ChildModel rule.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
enum Property:
'ONE;
grammar org.xtext.example.mydsl2.MyDsl2 with org.xtext.example.mydsl.MyDsl
generate myDsl2 "http://www.xtext.org/example/mydsl2/MyDsl2"
ParentModel:
property=Property;
grammar org.xtext.example.mydsl3.MyDsl3 with org.xtext.example.mydsl.MyDsl
generate myDsl3 "http://www.xtext.org/example/mydsl3/MyDsl3"
import "http://www.xtext.org/example/mydsl2/MyDsl2" as parent
ChildModel:
ParentProperty;
fragment ParentProperty returns parent::ParentModel:
property=Property; // Error here.
Note that the fragment rule was used to avoid the Generated package 'myDsl3' may not be empty error and is not necessary to trigger the issue:
ChildModel returns parent::ParentModel:
property=Property; // Error here as well.
In this case there is no subclass at all, yet the error persists, even if the generate directive was removed from the grammar entirely.
Attached gradle setup reproducing the issue: org.xtext.example.mydsl.parent.zip
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached Gradle setup and reproduce the error using the MyDsl, MyDsl2, and MyDsl3 grammar examples. Trace grammar inheritance, imported packages, and enum property resolution around the fragment or ChildModel rule. Done means a property using the base grammar's enum is accepted in the external ParentModel scenario without the incompatible-type error.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100