eclipse-xtext / eclipse-xtext/xtext

Cannot use enum from base model for property of external model element

Open
#2,433 4 comments 0 reactions 0 assignees View on GitHub

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 enum definition
  • MyDsl2 - a grammar inheriting from the base, containing a ParentModel with a property using the enum from the base grammar
  • MyDsl3 - a grammar inheriting from the base, containing a ChildModel that is a subclass of ParentModel

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.