Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » spurious type conflicts when importing two related packages in an Xtext grammar
spurious type conflicts when importing two related packages in an Xtext grammar [message #1405931] Fri, 08 August 2014 14:32 Go to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 23
Registered: April 2012
Junior Member
I have two xcore files and a dependency between them:

a.xcore
b.xcore -> a.xcore

a.xcore defines a class ClassInA. b.xcore defines a ClassInB which has a reference myA to a.ClassInA.

Since I wanted to import them in my Xtext grammar, I created a genmodel/ecore for each, and registered each generated package/genmodel in the MWE workflow.

However, in my grammar (which imports both "a" and "b"), in the rule for ClassInB, which includes a reference to ClassInA, like this:

ClassInB:
'B' myA=[ClassInA];

I get an error like this:

Cannot find compatible feature myA in sealed EClass ClassInB from imported package b: The existing reference 'myA' has an incompatible type 'ClassInA'. The expected type is 'ClassInA'.

I debugged this a bit and it turns out the cause is that there are multiple definitions of ClassInA (akin to a ClassCastException when the same class is loaded by two classloaders), causing the type clash. I guess the reason is that each imported Xcore/ECore model gets its own copy of the model elements, including those obtaining via cross-package references, instead of sharing them.

Is this a bug or a mistake on my part? Any workarounds?

Thanks.

[Updated on: Fri, 08 August 2014 14:38]

Report message to a moderator

Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1405941 is a reply to message #1405931] Fri, 08 August 2014 15:02 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 23
Registered: April 2012
Junior Member
Seems similar to:

https://www.eclipse.org/forums/index.php/m/1350708/
https://www.eclipse.org/forums/index.php/m/1401265/
https://www.eclipse.org/forums/index.php/m/1114519/
https://www.eclipse.org/forums/index.php/m/1228857/
https://bugs.eclipse.org/bugs/show_bug.cgi?id=439682

It seems a pretty common issue, with no suggested workaround. So, is that a known limitation (cannot import related packages), or an actual bug?
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406032 is a reply to message #1405941] Fri, 08 August 2014 20:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13270
Registered: July 2009
Senior Member
how does your workflow look like?

you you only register genmodel or do you loadresource stuff as well
e.g. as it is done here https://github.com/LorenzoBettini/xsemantics/blob/master/plugins/it.xsemantics.dsl/src/it/xsemantics/dsl/GenerateXsemantics.mwe2


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406045 is a reply to message #1406032] Fri, 08 August 2014 21:36 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 23
Registered: April 2012
Junior Member
Christian,

No loadedResource entries, just package/genmodel registrations, one for each pair of imported model:
bean = StandaloneSetup {
	scanClassPath  = true
	platformUri = "${runtimeProject}/.."
	registerGeneratedEPackage = "xmbase.XmbasePackage"
	registerGeneratedEPackage = "xmbehavior.XmbehaviorPackage"
	registerGeneratedEPackage = "xmstate.XmstatePackage"
	registerGeneratedEPackage = "xmcomplete.XmcompletePackage"
	registerGenModelFile = "platform:/resource/xmodel/model/xmbase.genmodel"
	registerGenModelFile = "platform:/resource/xmodel/model/xmbehavior.genmodel"
	registerGenModelFile = "platform:/resource/xmodel/model/xmstate.genmodel"
	registerGenModelFile = "platform:/resource/xmodel/model/xmcomplete.genmodel"
}


Should there be loadedResource entries as well? The Xtext DSL project wizard did not generate any. If so, for which files (the example you poined at has a mix of xcore/ecore/genmodel files).
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406180 is a reply to message #1406045] Sat, 09 August 2014 08:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13270
Registered: July 2009
Senior Member
i think the loadresource thing is a specialty for xcore stuff

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406195 is a reply to message #1406180] Sat, 09 August 2014 09:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13270
Registered: July 2009
Senior Member
pps: maybe it helps to have only one genmodel

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406265 is a reply to message #1406195] Sat, 09 August 2014 14:22 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 23
Registered: April 2012
Junior Member
I tried one genmodel only (that is what triggered the creation of the 'xmcomplete.xcore' model). But then, contrary to my intuition, the grammar would have access to only classes defined xmcomplete.xcore/ecore/genmodel. Those packages referred to by xmcomplete (xmbase, xmbehavior and xmstate) would not be available to be referenced in the DSL xtext file.

Just to confirm something: does the mwe2 file affect how the Xtext file is processed/validated? Or is it only used for the generation of code based on the Xtext file?
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406293 is a reply to message #1406265] Sat, 09 August 2014 16:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13270
Registered: July 2009
Senior Member
yes. it is used to build up emfs world of models/genmodels etc

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 09 August 2014 16:32]

Report message to a moderator

Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406294 is a reply to message #1406293] Sat, 09 August 2014 16:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13270
Registered: July 2009
Senior Member
p.S: with one genmodel i meant: on genmodel that includes/refereces the other ones or that contains all packages

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406332 is a reply to message #1406294] Sat, 09 August 2014 18:57 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 23
Registered: April 2012
Junior Member
Thanks, still at loss here.

Created only one genmodel that references the other genmodels, and again, any element from the referred genmodels that refers an element of another genmodel causes the same problem:

- modelA
- modelB -> modelA
- modelC
-> modelA
-> modelB

- grammar based on modelC -> type clash errors for any rules for elements from modelB that refer to elements from modelA.

In an effort in trying to isolate the problem, I copied the xtext file to a new base Xtext project (just the grammar, nothing else), and the problem ended up (after doing the clean/build dance) disappearing from that project.

Will see if I can create a full-blown Xtext project that with that grammar that won't show the problem.

If you want to take a look yourself, I committed it the two projects (the one with the abstract syntax and the one with the grammar) here:

https://bitbucket.org/abstratt/sandbox/src/master/compositedsl/?at=master
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406493 is a reply to message #1406332] Sun, 10 August 2014 07:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13270
Registered: July 2009
Senior Member
can you file a bug with an example attached

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406762 is a reply to message #1406493] Mon, 11 August 2014 03:01 Go to previous message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 23
Registered: April 2012
Junior Member
Done, thanks for your help, Christian:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=441473
Previous Topic:activating debug messages
Next Topic:Trying to use types that are only imported via import statement
Goto Forum:
  


Current Time: Wed Dec 11 11:40:39 GMT 2019

Powered by FUDForum. Page generated in 0.02507 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top