Skip to main content



      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 10:32 Go to next message
Eclipse UserFriend
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 10:38] by 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 11:02 Go to previous messageGo to next message
Eclipse UserFriend
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 16:42 Go to previous messageGo to next message
Eclipse UserFriend
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
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 17:36 Go to previous messageGo to next message
Eclipse UserFriend
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 04:26 Go to previous messageGo to next message
Eclipse UserFriend
i think the loadresource thing is a specialty for xcore stuff
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 05:13 Go to previous messageGo to next message
Eclipse UserFriend
pps: maybe it helps to have only one genmodel
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 10:22 Go to previous messageGo to next message
Eclipse UserFriend
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 12:31 Go to previous messageGo to next message
Eclipse UserFriend
yes. it is used to build up emfs world of models/genmodels etc

[Updated on: Sat, 09 August 2014 12:32] by 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 12:34 Go to previous messageGo to next message
Eclipse UserFriend
p.S: with one genmodel i meant: on genmodel that includes/refereces the other ones or that contains all packages
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 14:57 Go to previous messageGo to next message
Eclipse UserFriend
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 03:03 Go to previous messageGo to next message
Eclipse UserFriend
can you file a bug with an example attached
Re: spurious type conflicts when importing two related packages in an Xtext grammar [message #1406762 is a reply to message #1406493] Sun, 10 August 2014 23:01 Go to previous message
Eclipse UserFriend
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: Sun Jul 27 11:11:28 EDT 2025

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

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

Back to the top