Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370525

Summary: [xtext][model inference] cannot extend grammar with generated model
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: kavitha.ks83, schauer, sebastian.zarnekow, sven.efftinge
Version: 2.2.1   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Knut Wannheden CLA 2012-02-03 02:56:33 EST
There is a problem with extending grammars from which an EPackage is derived. It results in an error "Cannot add supertype 'X' to sealed type 'X'. (ErrorCode: CannotCreateTypeInSealedMetamodel)".

The base grammar is defined as follows:

grammar org.xtext.example.mydsl.MyDsl1 with org.eclipse.xtext.common.Terminals

generate myDsl1 "http://www.xtext.org/example/mydsl/MyDsl1"
//import "http://www.xtext.org/example/mydsl/MyDsl1"

Model:
       greetings+=Greeting*;

Greeting:
       'Hello' name=ID '!';

The derived grammar is:

grammar org.xtext.example.mydsl.MyDsl2 with org.xtext.example.mydsl.MyDsl1

import "http://www.xtext.org/example/mydsl/MyDsl2" as mydsl2
 
Model returns mydsl2::Model2:
       greetings+=Greeting*;

The EPackage mydsl2 only contains a single EClass Model2 which extends mydsl1::Model. Both the editor and the generator end up reporting the following problem: Cannot add supertype 'Model' to sealed type 'Model2'. (ErrorCode: CannotCreateTypeInSealedMetamodel).

A workaround is to also have the base grammar import the mydsl1 EPackage instead of generating it.
Comment 1 Sven Efftinge CLA 2012-02-03 03:24:24 EST
The references in MyDsl2 to MyDsl1 need to be absolute platform:/resource / uris. Is that the case?
Comment 2 Knut Wannheden CLA 2012-02-03 10:12:22 EST
No, as in the description MyDsl2 only references the MyDsl1 grammar directly (by its qualified name), not the EPackage. Adding an import for the generated EPackage using a platform:/resource URI is not possible:

import "platform:/resource/org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl/MyDsl1.ecore"

It results in the following error: "Metamodels that have been generated by a super grammar must be
   referenced by nsURI: http://www.xtext.org/example/mydsl/MyDsl1".

Importing the MyDsl1 EPackage by its nsURI doesn't make any difference. I.e. the same error as originally reported remains.
Comment 3 Sebastian Zarnekow CLA 2012-02-04 04:32:45 EST
I can imagine that the proxies MyDsl2.ecore resolve to the generated *.ecore file before the super grammar inferred the ecore model that should be the actual resolve target. Nasty :-(