Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 347171 - [Xtext] GrammarAccess causes ClassCastException when a subgrammar redefines a rule with the same name as in supergrammar
Summary: [Xtext] GrammarAccess causes ClassCastException when a subgrammar redefines a...
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 1.0.1   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 366786 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-05-25 11:04 EDT by Lothar Wendehals CLA
Modified: 2017-10-31 11:18 EDT (History)
8 users (show)

See Also:
sebastian.zarnekow: juno+


Attachments
Eclipse projects with example to reproduce the CCE (1.29 MB, application/x-zip-compressed)
2011-05-25 11:07 EDT, Lothar Wendehals CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lothar Wendehals CLA 2011-05-25 11:04:09 EDT
Build Identifier: Helios, Xtext 1.0.2

A grammar ConcreteDSL extends grammar AbstractDSL. Both grammars use an external model. Grammar AbstractDSL defines Rule Model, grammar ConcreteDSL redefines Model with different structure. When calling AbstractDSLGrammarAccess.getRuleModel(), it throws a ClassCastException.

Reproducible: Always

Steps to Reproduce:
I will attach an example.
Comment 1 Lothar Wendehals CLA 2011-05-25 11:07:34 EDT
Created attachment 196562 [details]
Eclipse projects with example to reproduce the CCE
Comment 2 Lothar Wendehals CLA 2011-05-25 11:14:59 EDT
This would case the CCE:

AbstractDSL:
Model returns abstractDSL::Model:
	greetings+=Greeting*;

ConcreteDSL:
Model returns abstractDSL::Model:
	greetings+=Greeting*
        text=STRING;


Hint:
Can easily be avoided by using a different name within the subgrammar.

AbstractDSL:
Model returns abstractDSL::Model:
	greetings+=Greeting*;

ConcreteDSL:
ConcreteModel returns abstractDSL::Model:
	greetings+=Greeting*
        text=STRING;
Comment 3 Ed Willink CLA 2011-10-26 12:55:27 EDT
(In reply to Bug 347171 comment #1)
> Most likely related to bug 347171

Yes this looks very like a duplicate.

(In reply to comment #2)
> Hint:
> Can easily be avoided by using a different name within the subgrammar.

Except when the redefine is a deliberate design for re-use.
Comment 4 Sebastian Zarnekow CLA 2011-11-09 14:45:25 EST
Not 2.1
Comment 5 Sebastian Zarnekow CLA 2011-12-19 05:03:15 EST
*** Bug 366786 has been marked as a duplicate of this bug. ***
Comment 6 Kai Kreuzer CLA 2012-01-12 04:15:32 EST
Note that bug 366786 describes a much more common use case - the adaption of Xbase, which is likely to happen very often in the future as many DSLs make use of Xbase. This might shift the priority of this issue.
Comment 7 Kai Kreuzer CLA 2012-02-14 05:07:18 EST
Is there any chance that this bug will be ever addressed?
Or is it simply not wished that existing grammar rules are overridden by subgrammars (especially in the case of Xbase)?
Comment 8 Sebastian Zarnekow CLA 2012-02-14 05:13:41 EST
(In reply to comment #7)
> Is there any chance that this bug will be ever addressed?
> Or is it simply not wished that existing grammar rules are overridden by
> subgrammars (especially in the case of Xbase)?


Will likely be fixed for Juno. Unlikely before M6.
Comment 9 Ed Willink CLA 2012-03-27 11:20:03 EDT
(In reply to comment #8)
> Will likely be fixed for Juno. Unlikely before M6.

Ping. M6 is done. It would be really good to see a fix for this since when using the new Serializer, there is a significant regression in useable behaviour for Complete OCL.
Comment 10 Michael Vorburger CLA 2012-03-28 00:39:24 EDT
Pong! We have an internal project on hold because of / waiting for this... (bug 366786). Would love to see progress - will help testing.
Comment 11 Sebastian Zarnekow CLA 2012-04-29 13:47:16 EDT
Preliminary scheduled for M7. Not sure if it'll make it, though.
Comment 12 Sven Efftinge CLA 2012-04-30 07:32:37 EDT
pushed to master. GrammarAccess now always use the grammar they were generated for.
Comment 13 Kai Kreuzer CLA 2012-05-01 05:52:42 EDT
I am afraid I have to ask to reopen this issue.

The class cast exception is gone, but I am now getting

java.lang.RuntimeException: The context 'XMemberFeatureCall_XMemberFeatureCall_1_1_0_0_0' is not valid for type 'XNumberLiteral'
Recommended contexts for type 'XNumberLiteral': XMemberFeatureCall_XMemberFeatureCall_1_1_0_0_0

I assume the problem is within the class Abstract[supergrammar]SemanticSequencer here as it compares the context with object identity (==) instead of object equals.

To reproduce the problem, please see the junit test that I have provided at https://bugs.eclipse.org/bugs/show_bug.cgi?id=366786#c0, which is available on Github (https://github.com/openhab/xtext-tests).
Comment 14 Sebastian Zarnekow CLA 2012-05-01 07:01:36 EDT
The equality comparison is unlikely causing the issue.

Reopened for further investigation.
Comment 15 Sven Efftinge CLA 2012-05-03 03:45:47 EDT
(In reply to comment #13)
> I am afraid I have to ask to reopen this issue.
> 
> The class cast exception is gone, but I am now getting
> 
> java.lang.RuntimeException: The context
> 'XMemberFeatureCall_XMemberFeatureCall_1_1_0_0_0' is not valid for type
> 'XNumberLiteral'
> Recommended contexts for type 'XNumberLiteral':
> XMemberFeatureCall_XMemberFeatureCall_1_1_0_0_0
> 
> I assume the problem is within the class
> Abstract[supergrammar]SemanticSequencer here as it compares the context with
> object identity (==) instead of object equals.
> 
> To reproduce the problem, please see the junit test that I have provided at
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=366786#c0, which is available on
> Github (https://github.com/openhab/xtext-tests).

I've opened a separate ticket for this. See bug #378325
Comment 16 Eclipse Webmaster CLA 2017-10-31 11:06:50 EDT
Requested via bug 522520.

-M.
Comment 17 Eclipse Webmaster CLA 2017-10-31 11:18:15 EDT
Requested via bug 522520.

-M.